Object Declaration and Access Class Members in JAVA


Object declaration is necessary to access class members in JAVA. From previous video you have learned how to declare class in JAVA (). This video will teach you the way to declare an object of a class, initialize it with the help of new keyword and finally access class members.

After watching this video you will be able to-

  • Write main function in class.
  • Declare an object of a class.
  • Instantiate object.
  • Access class members using object.
  • Explain the use of dot operator.
  • Explain the use of new keyword.
  • Initialize the property of class in class declaration

Syntax to declare an object for a class:-

<class_name> <object_name>;

new keyword is used to instantiate class object. Syntax to instantiate an object is:

<object_name> = new <class_name>

dot (.) operator is required to access class members using object. Syntax to access a class member is:


class employee
	  int empID=5;
	  void showEmpID()
	  public static void main(String args[])
		  employee e; // object declaration
		  e=new employee();


How's this tutorial?


Please enter your comment!
Please enter your name here