Object and Class in java (JNNC Technologies)



In this post, we will learn about Object and class in java. As Java is an object-oriented programming language, we need to design our program using Objects and classes.
Object: An entity that has state and behavior may be termed as Object.
For example: Employee has state with name, age and department, and behavior such as working on the assignment.
Class: A class is a blueprint/template that defines state and behavior of objects.
For example: Employee is a class in above example.
Object is an instance of class: As object are created on the basis of blueprint/template that class provides, Object is an instance of the class.
Let’s create a simple class:
Below diagram will explain the structure of class:Class Structure
Let’ s see an example of Object now:
You can create object of above class as below:
Objects are stored in heap memory.
When above statement gets called, physical object is created in the memory as below:
Object creation 1
Now let’s create two objects i.e. employee1 and employe2 and set name and age for these two objects.
These two objects will be created in memory as below:
Object creation 2
Object are created using constructor with the help of new operator. We will see more about in subsequent tutorials.
that’s all about Object and class in java.
Previous
Next

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();