Such a method is called a class method . Class methods are not associated with an instance of a class. Two or more methods within a class can share the same name. This offers programmer flexibility because the same mental construct can be used for different data types. Constructors A constructor is a special kind of method that creates an object and usually sets initial values for instance variables.
Constructors always have the same name as the corresponding class.
The different components have the same semantics as those of methods. Usually classes have several constructors that are overloaded. The first constructor uses a default size as shown in the example of unit 1, the second constructor has an explicit size attribute. The first statement of a constructor body is special. There are no explicit destructors to be specified by the programmer because Java provides an automatic garbage collection mechanism.