class is the only logical entity whereas Object is the physical as well as a logical entity.
Class: Class is a blueprint which is containing only a list of variables and methods and no memory is allocated for them. A class is a group of objects that has common properties.
A class in java contains:
- Data Member
- Method
- Constructor
- Block
- Class and Interface
Object:
Object is an instance of a class, object has state and behaviors.
An Object in java has three characteristics:
- State
- Behavior
- Identity
State: Represents data (value) of an object.
Behavior: Represents the behavior (functionality) of an object such as deposit, withdrawal, etc.
Identity: Object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. But, it is used internally by the JVM to identify each object uniquely.
Class is also can be used to achieve user-defined data types.
Aeal-life example of object and class
In the real world, many examples of objects and classes like dog, cat, and cow belong to animal's class. Each object has a state and behaviors. For example, a dog has a state:- color, name, height, age as well as behaviors:- barking, eating and sleeping.
Vehicle class
Car, bike, truck all belongs to vehicle class. These Objects have also different states and behaviors. For Example, a car has a state - color, name, model, speed, Mileage. as we; as behaviors - distance travel.
Syntax For declaring a class
class Class_Name
{
data members;
methods;
}
Program:
class Employee { int eid; // data member (or instance variable) String ename; // data member (or instance variable) eid=100; ename="Zoya"; public static void main(String args[]) { Employee e=new Employee(); // Creating an object of class Employee System.out.println("Employee ID: "+e.eid); System.out.println("Name: "+e.ename); } }Output:
Employee ID: 100 Name: Zoya- Progamming is what actually means ?
- What is software development ?
- How we categorized software development in different manner.
C Plus Plus
Python
Java Development
Web Designing
Javascript
Mysql
Oracle