OOP Concepts in Java: Inheritance, Overloading and Overriding

Method overloading in Java is the practice of defining two or more methods in the same class with the same name but different parameter lists. The Java compiler selects the correct method at compile time based on the number, type, or order of arguments. This is compile-time polymorphism and is one of the most tested OOP concepts in Java interviews.

Overloading in Java sits at the heart of every serious Java interview, from campus placements at TCS and Infosys to technical rounds at product companies. It is one of the clearest demonstrations of compile-time polymorphism and connects directly to the broader OOP framework Java is built on.

  • Overloading is resolved at compile time; overriding is resolved at runtime through dynamic method dispatch.
  • Java supports single inheritance via extends and simulates multiple inheritance through implements (interfaces), avoiding the diamond problem.
  • The four OOP pillars — inheritance, polymorphism, encapsulation, abstraction — map directly to Java keywords: extends, implements, private, abstract.
  • Java is not a purely object-oriented language because it has primitive types like int and boolean.
  • Access specifiers (private, default, protected, public) control visibility and are tested in almost every OOPs interview question set.

The Four Pillars of OOP in Java

Every object-oriented feature of Java builds on four ideas. Understanding them as a connected system, not as isolated definitions, is what separates candidates who clear interviews from those who do not.

Inheritance

Inheritance lets a child class acquire the fields and methods of a parent class using the extends keyword. A Dog class can extend Animal and automatically get its breathe() method without rewriting it. This is the “is-a” relationship in Java.

Java supports single inheritance for classes, meaning one class can extend only one other class. It supports multilevel inheritance (A extends B, B extends C) and hierarchical inheritance (multiple children from one parent). Hybrid and multiple class inheritance are deliberately excluded, and the next section explains exactly why.

Encapsulation and Data Hiding

Hiding implementation details is called encapsulation. You wrap data (instance variables) inside a class and expose it only through getter and setter methods. A real-world example: your bank’s mobile app shows your balance but never exposes the raw database query behind it.

In Java, you mark instance variables private and provide public getters and setters. That is encapsulation in practice. Data hiding is the result: the internal state cannot be corrupted by outside code. Access specifiers and access modifiers in Java, specifically private, default, protected, and public, are the mechanism that makes this work.

Abstraction

Abstraction hides complexity and shows only what is necessary. Java implements it through abstract classes and interfaces. An abstract class can have both concrete and abstract methods; an interface (pre-Java 8) could only have abstract methods, though Java 8 introduced default and static methods in interfaces.

The implements keyword in Java connects a class to an interface contract. Java interface variables are implicitly public static final, which is a detail that trips up many students in written tests.

Polymorphism

Polymorphism means “many forms.” Java has two types: compile-time polymorphism (overloading in Java) and runtime polymorphism (method overriding with dynamic dispatch). Both are tested constantly in OOPs questions for interviews at Indian IT companies and product startups alike.

Overloading vs Overriding: A Direct Comparison

Method overloading and method overriding in Java are the most confused pair in any OOP syllabus. The table below fixes that.

Feature Method Overloading Method Overriding
Resolution time Compile time Runtime
Class requirement Same class Parent and child class
Method signature Must differ (parameters) Must be identical
Return type Can be different Must be same or covariant
Access modifier No restriction Cannot be more restrictive
Static methods Can be overloaded Cannot be overridden (method hiding)
Polymorphism type Compile-time Runtime
Keyword used None required @Override annotation (recommended)

A question that catches people out: can a static method be overridden? No. If a subclass defines a static method with the same signature as the parent’s static method, it is called method hiding, not overriding. Dynamic dispatch does not apply to static methods because they are bound at compile time.

How to Create an Object in Java

You create an object using the new keyword followed by a constructor call: Dog d = new Dog();. The new keyword allocates heap memory, and the constructor initialises the object’s state.

A parameterized constructor in Java accepts arguments so you can set instance variable values at creation time: Dog d = new Dog("Labrador", 3);. If you do not write any constructor, Java provides a default no-arg constructor automatically. The moment you write a parameterized constructor, that default disappears unless you explicitly add it back.

Method Overloading in Java: A Simple Example

The following example shows overloading in Java with three versions of an add() method in the same class:

class Calculator {
    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }
    int add(int a, int b, int c) { return a + b + c; }
}

The compiler picks the correct version based on the argument types and count passed at the call site. Return type alone cannot distinguish overloaded methods in Java.

Dynamic Method Dispatch in Java

Dynamic method dispatch is Java’s mechanism for runtime polymorphism. When a parent class reference holds a child class object, the JVM decides at runtime which overridden method to call based on the actual object type, not the reference type.

Java does not have a virtual keyword (unlike C++), but every non-static, non-final, non-private method in Java is effectively virtual. The JVM’s method table handles dispatch automatically. This is why Java implements virtual function behaviour by default, without requiring an explicit keyword.

According to the TIOBE Index (June 2025), Java remains the third most popular programming language globally, used in over 65% of enterprise backend systems. Understanding dynamic dispatch is non-negotiable for anyone targeting Java developer roles.

According to the JetBrains State of Developer Ecosystem 2024 survey, 62% of Java developers work in enterprise applications and 48% cite OOP design patterns as the skill they most want to deepen. Knowing why multiple inheritance is excluded from Java is not trivia. It reflects how the language architects thought about maintainability at scale.

According to NASSCOM’s FY2025 India Tech Talent Report, Java remains the most in-demand backend language for IT services hiring in Bengaluru, Hyderabad, and Pune, with entry-level Java developer roles offering starting packages between Rs 4.5 LPA and Rs 7 LPA at Tier-1 IT firms.

Association in Java

Inheritance is not the only relationship between classes. Association in Java describes a “has-a” or “uses-a” relationship. A Car has an Engine. This can be aggregation (loose coupling, where the engine can exist without the car) or composition (tight coupling, where the engine is destroyed with the car). These relationships are tested in senior Java interviews and system design rounds.

Why Java Does Not Support Multiple Inheritance

Java deliberately dropped multiple class inheritance to avoid the diamond problem. If class C inherits from both A and B, and both A and B have a method called display(), the compiler cannot determine which version C should inherit. This ambiguity creates unpredictable behaviour and bugs that are genuinely hard to trace.

Java’s solution is clean: interfaces. A class can implement multiple interfaces using the implements keyword, and since interfaces historically did not carry implementation, there was no conflict. With Java 8’s default methods, a new ambiguity arose, but Java handles it by forcing the implementing class to override the conflicting method explicitly. So multiple inheritance is not supported in Java for classes, but it is available for interfaces with explicit conflict resolution.

The extends and implements keywords in Java serve distinct roles. extends is for single class inheritance or interface-to-interface extension. implements is for a class adopting one or more interface contracts. Mixing them up in an interview is an immediate red flag.

If you are building your Java skills alongside other technical foundations, the 3.0 University guide on top skills every college student must learn before graduation puts programming in context with communication, data analysis, and cloud basics that employers actually test for.

For students exploring where Java skills can take them professionally, the 3.0 University breakdown of entry-level jobs for teens and graduates covers roles where Java knowledge gives you a measurable edge over candidates with only Python experience.

Frequently Asked Questions

What is method overloading in Java?

Method overloading in Java means writing two or more methods in the same class with the same name but different parameter lists (different number, type, or order of parameters). The compiler selects the correct version at compile time. It is a form of compile-time polymorphism and has no effect on the return type alone.

What is the difference between overloading and overriding?

Overloading happens within the same class and is resolved at compile time. Overriding happens between a parent and child class and is resolved at runtime through dynamic method dispatch. Overloading changes the method signature; overriding keeps it identical. Static methods can be overloaded but not overridden, only hidden.

Why does Java not support multiple inheritance?

Java avoids multiple class inheritance because of the diamond problem: when two parent classes have a method with the same name, the compiler cannot decide which version the child class inherits. Java solves this with interfaces, which allow a class to implement multiple contracts. Since Java 8, conflicting default methods must be explicitly overridden by the implementing class.

Is Java a purely object-oriented language?

No. Java has eight primitive data types: int, byte, short, long, float, double, char, and boolean. These are not objects. Purely object-oriented languages like Smalltalk treat everything as an object. Java is object-oriented but not purely so, which is a common OOP interview question with a clear, specific answer.

What is dynamic method dispatch in Java?

Dynamic method dispatch is the process by which Java resolves overridden method calls at runtime rather than compile time. A parent class reference pointing to a child class object will execute the child’s version of the overridden method. This is how Java achieves runtime polymorphism without requiring an explicit virtual keyword like C++ does.

Can we overload the main method in Java?

Yes. You can overload the main method in Java by defining additional main methods with different parameter lists. However, the JVM will only call the standard public static void main(String[] args) as the program entry point. The overloaded versions must be called explicitly from within the code like any other method.

Where to Go From Here

Knowing these concepts cold gives you a real advantage in campus placement rounds and technical interviews. The next step is writing actual code: build a small Java project that uses inheritance, overloading in Java, and an interface to see how these ideas interact under real constraints, not just in definitions.

If you are weighing which direction to take your tech career, the 3.0 University article on how to choose the right career path after graduation in 2026 is worth reading before you commit to a specialisation. Java is foundational, but where you apply it (backend development, Android, fintech, enterprise software) shapes which OOP patterns you will use most.

For structured learning with certification outcomes, look at the 3.0 University list of top online courses for high-salary jobs and the curated free online learning platforms for students in 2025, both updated with current market demand data. If you are thinking longer term about which technical skills pay off most, the best career options in 2026 for students and professionals guide maps Java and OOP skills to specific job families and salary bands in India.

3.0 University offers online certification courses in Cybersecurity, Ethical Hacking, AI, Blockchain, and Web3 built for students, working professionals, and career switchers who want practical, industry-ready skills with recognised credentials. If you are ready to move beyond theory and build something that matters, explore the full course catalogue at 3.0 University and find the programme that fits where you want to go.

Last updated: September 2026. Reviewed by the 3University editorial team.

We create, review, and maintain educational content covering Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain, Web3, and emerging technologies.

Read More Articles