OOPs concepts in Java are the four core principles, encapsulation, inheritance, polymorphism and abstraction, that structure Java programs around objects and classes. They make code reusable, easier to maintain and closer to how real-world systems behave. Every Java developer, student and interview candidate needs to understand all four to write effective Java programs.
Java builds every program from classes and objects, which is why it is called an object-oriented programming language. Mastering these four pillars is the single most important step for any Java developer, whether you are preparing for a university exam or a job interview.
- Java’s four OOP pillars are: encapsulation, inheritance, polymorphism and abstraction, applied in almost every real Java project.
- According to the Stack Overflow Developer Survey 2024, Java ranks among the top five most-used programming languages globally, used by roughly 30% of professional developers.
- Java is not considered fully object-oriented because it supports eight primitive data types (int, char, boolean, etc.) that are not objects.
- Every OOP exam question, whether at a BTech, BCA or MCA level, traces back to at least one of these four concepts.
- Understanding OOPs concepts in Java also gives you a direct foundation for secure coding, ethical hacking and AI development.
Why Java Is an Object-Oriented Programming Language
Java was designed from day one around the idea that software should model real-world entities. James Gosling created Java at Sun Microsystems in 1995 with object-oriented programming at its core. When you write a Java program, you define a class, a blueprint, and then create objects from it. Every action in the program is performed by an object calling a method, not by a standalone function floating in global scope.
That design choice is why Java is called an object-oriented programming language. The language enforces structure. You cannot write a Java program without at least one class. Compare that to C, where you write functions directly, or to Python, where you can mix procedural and object-oriented styles freely. Our guide on how to write, compile and run a C program shows that procedural contrast clearly.
Is Java Fully Object-Oriented?
Strictly speaking, no. Java has eight primitive types, int, long, double, float, char, byte, short and boolean, that are not objects. Languages like Smalltalk, where literally everything is an object, are considered fully object-oriented. Java is widely described as predominantly object-oriented, and that distinction comes up in university viva questions more often than you would expect.
Java does provide wrapper classes (Integer, Double, Character, etc.) that let you treat primitives as objects when needed, so the gap is bridgeable in practice. The Oracle Java documentation explains this distinction clearly if you want the authoritative source.
Features of Object-Oriented Programming in Java
Beyond the four pillars, Java’s OOP model includes supporting features worth naming: classes and objects, constructors, method overloading, interfaces, and the this and super keywords. These are not separate pillars; they are the machinery that makes the four pillars work in real code. If you are just starting out and want to understand which tools you will need alongside Java, our guide on software development tools to learn first gives a practical starting checklist.
The Four Pillars of OOPs in Java Explained with Examples
The four pillars of OOPs in Java, encapsulation, inheritance, polymorphism and abstraction, each solve a specific problem in software design. Here is what each one does, why it matters and what it looks like in code.
1. Encapsulation
Encapsulation means bundling data (fields) and the methods that operate on that data inside a single class, and then restricting direct access from outside. You mark fields private and provide public getter and setter methods. This protects the internal state of an object.
Real example: a BankAccount class keeps its balance field private. External code can call getBalance() or deposit(amount) but cannot set balance = -5000 directly. That one rule prevents a whole category of bugs.
A common mistake beginners make is making all fields public to save time. That works until another class corrupts your object’s state and you spend hours debugging it. Encapsulation is the fix.
2. Inheritance
Inheritance lets one class acquire the fields and methods of another using the extends keyword. The class being inherited from is the parent (or superclass); the class that inherits is the child (or subclass).
Example: a Vehicle class has fields like speed and fuel. A Car class extends Vehicle and automatically gets those fields, then adds its own, like numberOfDoors. You write the shared logic once and reuse it everywhere.
Java supports single inheritance for classes, meaning a class can extend only one parent class. This is a deliberate design choice to avoid the diamond problem that C++ faces. Java uses interfaces to achieve multiple-inheritance-like behaviour, but that is a topic for its own page.
3. Polymorphism
Polymorphism means many forms. In Java, a single method name can behave differently depending on the object calling it or the arguments passed to it. There are two types of polymorphism in Java.
| Type | Also Called | Resolved At | Mechanism |
|---|---|---|---|
| Compile-time polymorphism | Static binding | Compile time | Method overloading |
| Runtime polymorphism | Dynamic binding | Runtime | Method overriding |
Method overloading means defining multiple methods with the same name but different parameter lists in the same class. Method overriding means a child class redefines a method from the parent class with the same signature. Overriding is the one that makes polymorphism powerful at runtime.
Polymorphism, encapsulation and inheritance together are the combination most frequently tested in Indian university exams and technical interviews at companies like TCS, Infosys and Wipro.
4. Abstraction
Abstraction hides complex implementation details and exposes only what the user needs to know. In Java, you achieve abstraction through abstract classes and interfaces.
An abstract class can have both abstract methods (no body, must be overridden) and concrete methods (with a body). A class declared abstract cannot be instantiated directly. You create a subclass that provides the missing method bodies, then instantiate that.
Think of a Shape abstract class with an abstract method calculateArea(). A Circle subclass overrides it with the actual formula. The user calls calculateArea() without caring how the math works internally. That separation is abstraction in action.
OOP Programs in Java: A Complete Working Example
The program below demonstrates all four pillars of OOPs in Java in one compact example. This is the type of OOP program asked in BSc CS and BTech Java practicals across Indian universities.
The structure uses an abstract class Employee (abstraction), a private salary field with getters and setters (encapsulation), a Manager subclass that extends Employee (inheritance), and an overridden displayRole() method that behaves differently per object (polymorphism).
// Abstraction: abstract class
abstract class Employee {
private double salary; // Encapsulation: private field
public Employee(double salary) {
this.salary = salary;
}
public double getSalary() { return salary; } // Getter
public void setSalary(double salary) { this.salary = salary; } // Setter
public abstract void displayRole(); // Abstract method
}
// Inheritance: Manager extends Employee
class Manager extends Employee {
private String department;
public Manager(double salary, String department) {
super(salary);
this.department = department;
}
@Override
public void displayRole() { // Polymorphism: method overriding
System.out.println("Manager of " + department + ", Salary: " + getSalary());
}
}
class Developer extends Employee {
public Developer(double salary) { super(salary); }
@Override
public void displayRole() {
System.out.println("Developer, Salary: " + getSalary());
}
}
public class Main {
public static void main(String[] args) {
Employee e1 = new Manager(85000, "Engineering");
Employee e2 = new Developer(72000);
e1.displayRole();
e2.displayRole();
}
}
When you run this, e1.displayRole() and e2.displayRole() produce different output even though both variables are typed as Employee. That is runtime polymorphism working exactly as intended.
If your program throws errors during execution, understanding how Java handles them is just as important as writing clean OOP code. Our article on Java exceptions and common runtime errors covers that in full.
OOP Interview Questions Actually Asked in Exams
Indian university exams and campus placement drives consistently test the same set of OOP questions. Here are the most common ones, with what the examiner is actually looking for.
- Explain the four pillars of OOP with examples. Write a short definition plus one concrete Java example for each. Do not just list names.
- What is the difference between method overloading and overriding? Overloading is compile-time; overriding is runtime. Same method name, different resolution.
- Can we instantiate an abstract class? No. You must create a concrete subclass first.
- What is the difference between an abstract class and an interface? Abstract classes can have state (fields) and concrete methods; interfaces (pre-Java 8) cannot. Java 8 and later interfaces can have default methods, but this is a nuance to mention separately.
- Why does Java not support multiple inheritance through classes? To avoid ambiguity when two parent classes have the same method. Java uses interfaces as a workaround.
If you are a BSc CS or MCA student building a broader picture of what you will study and where it leads, our pages on BSc Computer Science subjects and scope and jobs and salary after MCA give useful career context.
How OOP Compares to Procedural Programming in Java
Understanding object-oriented programming in Java is easier when you see it side by side with the procedural approach used in languages like C.
| Feature | Procedural (C) | Object-Oriented (Java) |
|---|---|---|
| Basic unit | Function | Class / Object |
| Data access | Global or passed as argument | Encapsulated inside objects |
| Code reuse | Function calls | Inheritance and composition |
| Scaling large systems | Difficult | Well-suited |
| Security | Limited data hiding | Encapsulation provides data hiding |
According to the TIOBE Index for 2024, Java consistently holds a top-five position in programming language popularity, driven largely by enterprise adoption in banking, e-commerce and Android development. The TIOBE Index measures language usage based on search engine queries across 25 sources.
The Stack Overflow Developer Survey 2024 also reports that Java developers in professional roles rank among the highest earners in India’s IT sector, with backend Java roles at mid-level commanding salaries between INR 8 and 18 LPA at companies like Infosys, HCL and Razorpay. That is not just a language fact; it is a career argument for learning OOP properly.
If you are deciding between career paths after mastering Java, the comparison of full stack developer vs software developer breaks down which direction suits different goals.
Frequently Asked Questions
What are OOPs concepts in Java?
OOPs concepts in Java are the four foundational principles, encapsulation, inheritance, polymorphism and abstraction, that define how Java organises code around objects and classes. They make programs modular, reusable and easier to debug. Every Java application, from a simple university project to a production banking system, uses at least one of these principles.
What are the 4 pillars of Java?
The four pillars of Java OOP are encapsulation (hiding data inside classes), inheritance (child classes reusing parent class code), polymorphism (one method behaving differently based on context) and abstraction (hiding implementation details behind a simplified interface). These are the four pillars tested in every Java exam and technical interview.
What is the difference between abstraction and encapsulation in Java?
Encapsulation hides the internal data of an object by making fields private and exposing them through getter and setter methods. Abstraction hides the implementation logic of a method, showing only what the method does, not how it does it. Encapsulation works at the data level; abstraction works at the design level. Both are core OOPs concepts in Java but solve different problems.
Is Java fully object-oriented?
No, Java is not fully object-oriented. It includes eight primitive data types, int, char, boolean, double and others, that are not objects. A fully object-oriented language treats everything, including numbers and booleans, as objects. Java’s wrapper classes like Integer and Boolean allow primitives to behave as objects when needed, but the primitives themselves are not objects by default.
What is polymorphism in Java with an example?
Polymorphism in Java means one method name can behave differently depending on the object or arguments involved. For example, a displayRole() method defined in a parent class Employee can produce different output when called on a Manager object versus a Developer object. This is runtime polymorphism achieved through method overriding, one of the most tested OOPs concepts in Java interviews.
Why is Java an object-oriented programming language?
Java is called an object-oriented programming language because its entire program structure is built around classes and objects. Every Java program must have at least one class, and all actions are performed through object method calls. The language was designed specifically to enforce OOP principles, unlike C, which is procedural, or Python, which supports multiple paradigms.
Next Steps After Learning OOPs Concepts in Java
You now have a complete picture of OOPs concepts in Java. The four pillars are not just exam topics; they are the mental model every Java developer uses every day. Here are three concrete steps to move forward this week.
- Write the example program above from scratch, without copying it, and modify it to add a third employee type. That one exercise cements all four pillars faster than re-reading notes.
- Pair OOP with exception handling. Read our guide on Java exceptions and common runtime errors so your OOP programs do not crash silently in production.
- Apply OOP to a real career track. Strong Java and OOP fundamentals are the entry point for secure coding, ethical hacking and AI development. If you want to build on this foundation with industry-recognised credentials, explore 3.0 University’s online certification courses in Cybersecurity, AI, Blockchain and Web3. If ethical hacking is your goal, the CEH v13 AI online course is a strong next step, and the OOP thinking you have built here directly supports the secure coding modules inside it.
Last updated: June 2025. Reviewed by the 3University editorial team.