Example for creating object for class square
// declaring object
S1= new square();
// instantiate object
First statement declares a reference type variable to store the object reference of square
type whereas second statements actually assigns the object reference to S1 variable.
These both statements can be combined in a single statement to create an object as
Square s1= new square();
With the above given method, we can create any number of objects for a class.
Constructor is the most important topic which comes into the mind as there is a discussion
about a class. Every class has at least one constructor. If a programmer does not explicitly
specify any constructor, there is always a default constructor for that class. As a object is
created, a constructor is invoked.
Important points for a constructor
Constructor has the same name as class.
There is no return type for a constructor even not void.
There can be multiple constructors for a single class.
If constructors are explicitly defined by the programmer then default construct-
or not comes in existence.