Syntax for creating the Instance:
<class ><instance> = new <class> ([< list of value>])
Examples :
Program P= new program (); // P is instance of the class
Program P; // P is variable of the class.
P = new Program (); // P is instance of the class.
Note: A variable of a class is a copy of a class that is not initialized where the instance of a class is a copy of a class that is initialized by using new keyword.
<class ><instance> = new <class> ([< list of value>])
Examples :
Program P= new program (); // P is instance of the class
Program P; // P is variable of the class.
P = new Program (); // P is instance of the class.
Note: A variable of a class is a copy of a class that is not initialized where the instance of a class is a copy of a class that is initialized by using new keyword.
- The instance of a class can be created under the same class or under other classes also whereas if we want to create the instance in the same class it can be created under any static block of the class, but generally we create instance under main method of the class because main is also a static method and more over the entry point of the program.
No comments:
Post a Comment