DEV Community

Cover image for What is object & class in java
Rahul Raj
Rahul Raj

Posted on

What is object & class in java

What is Object ?

Object is real world entity having properties and behaviors .
Eg : Pen is an object .

  • A pen can have properties like color, brand, height, and diameter, and a pen is used for writing purposes ( function/behavior of the pen).

  • Object is an instance of class .

  • Generally we create object with the help of new keyword .

  • new is dynamic memory allocation operator .

  • we can create more than one object of same class - no problem.

  • It is a physical entity .

What is class ?

A class is blueprint of object from which objects are created .

  • A class is nothing but a blueprint of a building. With that blueprint, we can create any number of buildings having the same structure.
  • A class contains fields, blocks, constructors, methods, and so on.
  • A class can not contain any executable Statement directly .
  • we can create class with class keywords .
  • Top level class either public or default .

Top comments (0)