Object Oriented Programming in Java
Let’s consider a scenario where we want to build a building .To build this building we require a plant or a blueprint. So imagine building is an object. To build any object , Java virtual machine needs a structure and that blueprint is a class.
Imagine object as a dog. Every object has two things . object knows something and object does something.
The three steps of object declaration ,creation and assignment
1)Declare a reference variable
Dog myDog;
Tells the JVM to allocate space for a reference variable myDog;
2) Create an object
new Dog();
Tells the JVM to allocate space for new Dog object on heap.
3) Link the object and references
Dog myDog =new Dog( );
Assign the new Dog to reference variable myDog.