Define class and object. Explain them with an example using java
Class: A class is a program construct which encapsulates data and operations on data. In object oriented programming, the class can be viewed as a blue print of an object.
Object: An object is a program construct that falls under a ‘classification’ (of a class) which has state and behavior.
For Example: Employee is an example of a class
A specific employee with unique identification is an example of an object.
class Employee
{
// instance variables declaration
// Methods definition
}
An object of employee is a specific employee
Employee vismay =new Employee();
One of the objects of Employee is referred by ‘vismay’