Object-Oriented Programming (OOP) is an approach that models a program after real-world objects. An object has data (attributes/fields) and behavior (methods). For example, a Student object can have data like name, age, and grade, along with behavior like study() and submitAssignment().
Java is a language built around OOP, with four core pillars.
• Encapsulation — controlling data and providing safe access to it
• Inheritance — a child class inheriting features from a parent class
• Polymorphism — letting one method behave differently depending on the object
• Abstraction — hiding unnecessary detail and showing only the important behavior
class Student {
String name;
void study() {
System.out.println(name + " is studying Java.");
}
}
public class Main {
public static void main(String[] args) {
Student student = new Student();
student.name = "Aung";
student.study();
}
}Student class is the blueprint. new Student() builds a Student object. The name field on the object gets set, and the study method gets called.
Aung is studying Java.Real-World Use
App entities like User, Product, Order, Payment, Course, and Lesson are all built using classes and objects.