Java Tutorial: 7(Classes & Objects In JAVA)

Class in JAVA

A class is like a container in JAVA which contains the methods and objects and also determines their behavior. Thus it acts like a template or blueprint for the objects.

Class Syntax:
   class NameOfClass
   {
        //Class body
        String a;
        int x;
   }

Objects in JAVA

In Java, the new keyword is used to create new objects.An entity that has state and behavior is known as an object and There are three steps when creating an object from a class:

Declaration − Declaring the Object.
Syntax - NameOfConstructor newobject;

Instantiation − The 'new' keyword is used which will do instantiation of the object.
Syntax - new newobject();

Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
Syntax - NameOfConstructor newobject = new NameOfConstructor();


Comments