In Java we have to always deal with objects, now let's understand what is object , how to define object in Java.
What is Object In Java ?
Object is an entity with STATE and Behavior.
Examples of Objects : Bike ,Mobile, Student,Laptop,Car etc.
If we consider Bike As Object , Bike Name is state , Bike Color is state , and Running is behavior of Bike,Starting is behavior of bike and stopping is also behavior of Bike.
In Java we say , Object is an Instance of class , it means we can create object using class.
What is class ?
A class is template or blueprint from which objects are created.
A class in java can contain fields(variables),Methods(Behaviors),blocks,constructors etc.
How To Create class in Java ?
Syntax To Create Class :
class College {
String collegeName="COEP";
public void getAdmission(){
System.out.println("In this method we have to write logic to get Admissions");
}
}
In above example , collegeName is a field and getAdmission is a method.