what is an object in java?

 what is an object in java?

well, an object is like a capsule that contains data and behavior. Objects are instances of classes and a class is like a template, like a blank form in which objects are created.


let's imagine an example of the class wizard.

an object or an instance of that class might be Gandalf. you can take the template class wizard. then fill in its data, and then you get the object Gandalf. Now Gandalf is an instance of the class wizard, where the properties or member variables have been filled in specific to him. and he exists in a space in memory allocated for a wizard.





so an object is a combination of two things:

object

-state of the object stored as member variables

-set of methods that give the object ability to perform certain tasks.


you may have guessed that objects are the foundation of object-oriented programming and Java. The reason they were created was to make programming feel intuitive, to mirror how we as humans experience the world.

Comments

Popular posts from this blog

Sri Lankan IT industry & companies

Find Odd & Even number - pseudocode