⏱️ 8 min read • Beginner Level • Lesson 43
Completed on . You can revise this lesson or continue to the next topic.
Object-Oriented Programming, commonly called OOP,
is a programming style where we solve problems by creating objects.
Java is strongly based on OOP concepts such as class, object,
encapsulation, abstraction, inheritance, and
polymorphism.
Before learning OOP concepts, you should understand Java variables, Java methods, and Java data types.
OOP stands for Object-Oriented Programming. It is a programming approach where a program is designed using objects. An object combines data and behavior into a single unit.
Java supports object-oriented programming.
OOP helps organize code using classes and objects.
It makes code reusable, secure, flexible, and easier to maintain.
Think of a real-world school system. A student has data such as name, roll number, and marks. A student also has actions such as study, attend exam, and show result. In OOP, we can represent this real-world student as an object.
Consider a banking application.
| Procedural Programming | Object-Oriented Programming |
|---|---|
| Focuses on functions | Focuses on objects |
| Less secure | More secure through encapsulation |
| Less reusable | Highly reusable |
| Difficult for large projects | Suitable for large applications |
An object is a real-world entity that has state and behavior.
For example, a laptop can be treated as an object:
| State / Data | Behavior / Action |
|---|---|
| Brand, RAM, Storage, Color | Start, Shutdown, Run Program |
A class is a blueprint or template used to create objects. It defines what data and methods an object will have.
For example, Student can be a class, and Ayan,
Sarah, and John can be objects of that class.
The following example creates a Student class and uses it to create an object.
class Student {
String name;
int rollNumber;
void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Roll Number: " + rollNumber);
}
}
public class StudentExample {
public static void main(String[] args) {
Student s1 = new Student();
s1.name = "Ayan";
s1.rollNumber = 101;
s1.displayDetails();
}
}
Output:
Name: Ayan Roll Number: 101
Student is a class.name and rollNumber are data members.displayDetails() is a method.s1 is an object of the Student class.Java OOP is mainly based on four important concepts:
Wrapping data and methods together and protecting data from direct access.
Hiding internal details and showing only essential features.
Acquiring properties and methods of one class into another class.
Performing one action in different ways.
Encapsulation means binding data and methods together inside a class. It also helps protect data by restricting direct access from outside the class.
A common way to achieve encapsulation in Java is by using private variables
and public getter/setter methods.
private
and providing controlled access through getter and setter methods.
Abstraction means hiding implementation details and showing only important information to the user.
For example, when you drive a car, you use the steering wheel, accelerator, and brake. You do not need to know the internal engine working every time you drive.
abstract classes and interfaces.
Inheritance allows one class to acquire the properties and methods of another class. It supports code reusability.
For example, Dog can inherit common properties from an Animal class.
extends keyword.
It helps in code reuse and creating parent-child relationships between classes.
Polymorphism means many forms. In Java, it allows one action to behave differently depending on the object or situation.
method overloading
and method overriding.
In the upcoming lessons, you will learn each OOP concept separately: Class and Object → Encapsulation → Inheritance → Polymorphism → Abstraction.
| Concept | Meaning | Real-Life Example |
|---|---|---|
| Object | Entity with state and behavior | Student, Laptop, Car |
| Class | Blueprint for creating objects | Student class for many student objects |
| Encapsulation | Wrapping data and methods together | Bank account with private balance |
| Abstraction | Hiding internal details | Using ATM without knowing internal process |
| Inheritance | One class acquiring features of another | Dog inherits from Animal |
| Polymorphism | One action with many forms | Different animals make different sounds |
What are the four pillars of OOP?
Encapsulation, Abstraction, Inheritance, and Polymorphism.
🧠 Test your understanding with a quick quiz
Topic: Oops-overview | Language: Java
class Student {
String name = "Ayan";
void display() {
System.out.println(name);
}
}
public class Test {
public static void main(String[] args) {
Student s1 = new Student();
s1.display();
}
}🎉 Great job! Continue learning Java OOP step by step.
Mark this lesson as completed to track your learning progress. To keep track across devices, please login and save your learning progress.
Discussion
Ask questions, share suggestions, or discuss this lesson.