Classes and Objects in Java with examples

A class is a blueprint or model based on which object is defined. A class cannot exists in real world but object can. A class is a physical idea where as object is an instance of the class.

An object is an entity that is having state and behavior or simply we can say object is anything that exists in the real world. An object will have properties and actions. Properties are represented by variables and Actions are represented by methods.

java objects containing variables and methods
Objects in Java
  • If you take a dog it will have properties like name, height, weight, age and actions like barking, running, biting etc.
  • We can't create a object without a class.
  • However we can create a class without a object for example Dinosaur
  • A class is a physical idea where as object is instance of class
  • Class code is stored in method area in JVM where as
  • Objects are created in heap in JVM

No comments:

Post a Comment