Learning Java Programming Made Easy
Java Object: Object is a variable which has states and behaviors, and it is an instance of the class.
ex.
A dog has
states - color, name, breed as well as
behaviors – wagging the tail, barking, eating.
Java Class: It is a collection of variables, objects, staetments, and functions which performs a specific function.
Java Object: Object is a variable which has states and behaviors, and it is an instance of the class.
ex.
A dog has
states - color, name, breed as well as
behaviors – wagging the tail, barking, eating.
Java Class: It is a collection of variables, objects, staetments, and functions which performs a specific function.
- A class is a template or blueprint that is used to create objects.
- Class representation of objects and the sets of operations that can be applied to such objects.
- The class consists of Data members and methods.
Primary purpose of a class is to held data/information. This is achieved with attributes which is also known as data members.
The member functions determine the behavior of the class i.e. provide definition for supporting various operations on data held in form of an object.
There are many differences between object and class. A list of differences between object and class are given below:
No. | Object | Class |
---|---|---|
1) | Object is an instance of a class. | Class is a blueprint or templatefrom which objects are created. |
2) | Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. | Class is a group of similar objects. |
3) | Object is a physical entity. | Class is a logical entity. |
4) | Object is created through new keyword mainly e.g. Student s1=new Student(); | Class is declared using class keyword e.g. class Student{} |
5) | Object is created many times as per requirement. | Class is declared once. |
6) | Object allocates memory when it is created. | Class doesn't allocated memory when it is created. |
7) | There are many ways to create object in java such as new keyword, newInstance() method, clone() method, factory method and deserialization. | There is only one way to define class in java using class keyword. |
No comments:
Post a Comment
Welcome, happy learning