Constructors: Public Class Public Public
Constructors: Public Class Public Public
Constructors
When discussing about classes, one of the most important sub topic would be
constructors. Every class has a constructor. If we do not explicitly write a
constructor for a class, the Java compiler builds a default constructor for that
class.
Each time a new object is created, at least one constructor will be invoked. The
main rule of constructors is that they should have the same name as the class.
A class can have more than one constructor.
Following is an example of a constructor −
Example
public class Puppy {
public Puppy() {
}
If we compile and run the above program, then it will produce the following result
−
Output
Passed Name is :tommy