Define class and object. Explain them with an example using java

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’
What is a method? Provide several signatures of the methods
What is a method? - A java method is a set of statements to perform a task. A method is placed in a class...
Difference between instance variable and a class variable
Difference between instance variable and a class variable - An instance variable is a variable which has one copy per object / instance. That means every object will have one copy of it...
Explain how to create instance of a class by giving an example
How to create instance of a class - Java supports 3 ways of creating instances...
Post your comment