Objects in Java

You need objects for accessing the members of the class. Let’s see how to declare an objects.

Syntax of Creating Objects:
class_name object_name;
object_name = new class_name();
CodeParent cp = CodeParent(); //Declaration, Instantiation, Initialization.

Accessing class members
Every time you create an object of the class, the new object gets a copy of every instance variable defined in its class. For accessing the class members check the below syntax,
Object_name.method_name(argument list);

CodeParent cp = new CodeParent();
cp.name = “Name1”;
cp.age = 50;

Points to Remember:

  • Every object of the class has its own copy of the variables declared with in the class.


Leave a Reply