What are Objects in Object Oriented Programming aka OOP?
This could be best way to answer what are Objects in Java, this is more than enough for a beginner level engineer, keep note of following information
Objects are instances of class, class defines blue prints and objects are things which are created based upon that blueprint.
Object is also known as instance in Java, e.g. when we say an instance of String class, we actually mean an object of String class.
Object has state and behaviour.
State: State is represented using instance variable and static variable.
Behaviour: And behaviours are implemented using methods in Java.
The things which differentiate two objects of same class are their states e.g. if we take two instances of String class 'A' & 'B' their contents are different which is nothing but their state.
There are several ways to create objects in Java, .e.g., Serialization. Cloning, Reflection, etc.
But the most common and easy way to create objects in Java is by using new() keyword.
When we create an object of any class in Java, its constructor gets called, which initializes object with its default or initial state.
Comments
Post a Comment