Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Core Java & Object-Oriented Architecture 22 mins read Free Lesson

Object-Oriented Programming: Classes & Inheritance

Master Encapsulation, Constructors, Inheritance with extends, and Method Overriding with @Override.

The 4 Pillars of OOP in Java

// Base Superclass
public class Employee {
    private String name;
    protected double salary;

    public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }

    public double calculateBonus() {
        return this.salary * 0.10;
    }
}

// Subclass with Inheritance
public class Manager extends Employee {
    public Manager(String name, double salary) {
        super(name, salary);
    }

    @Override
    public double calculateBonus() {
        return this.salary * 0.25; // Polymorphic override
    }
}