Java - Object-Oriented Programming (OOPS) Concept - Object & Class Tutorial
Object
Anything that has a state and behavior is known as an object. For example, a pencil, chair, mouse, keyboard, mobile, etc.
An object is created from the class.
Class
A class is a collection of objects.
public class ObjectExample {
public void m1(){
System.out.println("Hello Fresherbell");
}
public static void main(String[] args) {
ObjectExample message = new ObjectExample();
message.m1();
}
}
We can also use multiple objects
public class MultipleObjectExample {
public void m1(){
System.out.println("Hello Fresherbell");
}
public static void main(String[] args) {
MultipleObjectExample message1 = new MultipleObjectExample();
MultipleObjectExample message2 = new MultipleObjectExample();
message2.m1();
message2.m1();
}
}