public Test( )
A constructor in Java is similar to a method that is invoked when an object of the class is created.
Unlike Java methods, a constructor has the same name as that of the class and does not have any return type. For example,
class Test {
public Test() {
// constructor body
}
}
Here, Test()
is a constructor. It has the same name as that of the class and doesn't have a return type.