Tuesday 23 July 2013

What is Class and Object in Java

                                               
                                                        What is Class and Object in Java

Java is an object-oriented programming language.As a language that has the Object Oriented feature Java supports the following fundamental concepts:

Classes
Objects
Encapsulation
Inheritance
Polymorphism
Abstraction


Class:- A class is a template, blueprint(of Object) means you can create different object based on one class which varies in there property.

Object:-An object is an instance of a class. You can create many instances of a class.
e.g. if Car is a class than Hyundai,Nissan,Maruti Suzuki or Tata Motors can be considered as object because they are essentially a car but have different size, shape, color and feature.

Objects have states and behaviors:- State is represented by field in class 
e.g. numberOfGears, whether car is automatic or manual, car is running or stopped etc. 
On the other hand behavior is controlled by functions, also known as methods in Java 
e.g. start() will change state of car from stopped to started or running and stop() will do opposite.





For example, a car is an object. 

Its state includes current:

Speed
RPM
Gear
Direction
Fuel level
Engine temperature

Its behaviors include:

Change Gear
Go faster/slower
Go in reverse
Stop
Shut-off

Its identity is:

VIN
License Plate


*1. A class describes the data and the methods of its objects. Every object belongs to some class.
*2. An object contains data (instance variables) representing its state, and instance methods, which are the things it can do.


3 comments: