Friday, 26 February 2016

Object And Class In Java Tutorial : What is a Object : What is a Class : Difference Between Object and Class

Java-Objects & Classe

Objects and Class Differens : 

java images

Objects : An objects is anything that really exists in the world and can be distinguished from others. This definition specifies that every thing in this world is an object.
Ex: A Table, A ball, A dog, A person ETC… 
What is not an object : 
If something does not really exist, then it is not an object. 
Ex: Our thoughts, imagination, plan, idea etc…. 
Every object has properties and can perform certain actions. 
Ex: Let us take a person whose name is Ramu is an object because he exists physically. He has properties like name , age , sex etc… 
These properties can be represented by variables in our programming . 
Ex : string name ; 
        int age; 
       char sex: 
It is possible that some objects may have similar properties and actions. Such object belong to same category called a class. 
Ex : Not only Ramu, But also Ravi, Sita,Vijay etc… 
What is difference between a class and an objects? 
A class is a model for creating objects and does not exist physically. An object is any thing that exists physically. Both the class and objects contain variables and methods. 
Class : Let us create a class with the name person for which Ramu and sita are objects. A class is created by using the keyword, class. 
A class Describes the properties and actions performed by its objects. So, we write the properties (Variables) and actions (Methods) in this class as : 
Ex : Class Person 
      string name; 
      int age; 
      void talk() 
     void eat() 
A person is a class has two variables and two methods. This class code is stored in JVM’s method area, when we want to use this class, we should create an objects to the class 
Ex: person Ramu= new person(); 
Here Ramu is an object of person class. Object represents memory to store the actual data. 



Post a Comment