Java OOPs Interview Questions 2026: 32 Q&A With Code

What changed in 2026 drives
Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.
What I'd actually study for this
- 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
- 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
- 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
- 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken
Where most candidates trip up
The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.
Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.
Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~16 min
Object-oriented programming is the backbone of every Java technical round. Candidates report that OOP questions appear in almost every service-company interview (TCS, Infosys, Wipro, Accenture) and form the warm-up in product-company loops before the DSA grind begins. This guide collects 32 of the most repeated Java OOP questions, each with a full answer, runnable code, and the follow-up the interviewer usually asks next. Public preparation resources and the official Oracle Java documentation back the language behaviour shown here, confirm any version-specific detail on the official docs because behaviour can shift between Java releases.
Pair this with our Java Interview Questions 2026 master set and the Java Collections Interview Questions 2026 deep dive for full coverage.
Table of Contents
- Fundamentals (Q1 to Q10)
- Inheritance and Polymorphism (Q11 to Q20)
- Abstraction and Interfaces (Q21 to Q27)
- Advanced and Tricky (Q28 to Q32)
- Predict the Output
- Quick Revision Table
- Frequently Asked Questions
Fundamentals
Q1. What are the four pillars of OOP in Java? Easy
Q2. What is a class and what is an object? Easy
class Car { // blueprint
String model;
void drive() { System.out.println(model + " driving"); }
}
Car c = new Car(); // object on the heap
c.model = "Nexon";
c.drive(); // Nexon driving
Q3. What is encapsulation and how do you achieve it in Java? Easy
class Account {
private double balance; // hidden state
public double getBalance() { return balance; }
public void deposit(double amt) {
if (amt > 0) balance += amt; // validated write
}
}
The interviewer's follow-up is usually "why not make the field public?" Answer: a public field cannot enforce invariants such as a non-negative balance, and you cannot change the internal representation later without breaking callers.
Q4. What is a constructor? Can it be private? Easy
class Logger {
private static final Logger INSTANCE = new Logger();
private Logger() {} // private constructor
public static Logger get() { return INSTANCE; }
}
Q5. What is the difference between a default constructor and a parameterised constructor? Easy
Q6. What is the this keyword used for? Easy
class Point {
int x, y;
Point(int x, int y) { this.x = x; this.y = y; } // field vs parameter
Point(int x) { this(x, 0); } // constructor chaining
}
Q7. What is the difference between instance variables and static variables? Medium
class Counter {
static int total = 0; // shared
int id; // per object
Counter() { id = ++total; }
}
Q8. What is constructor overloading? Easy
Q9. Can a constructor be inherited? Medium
Q10. What is the order of execution: static block, instance block, constructor? Medium
class Demo {
static { System.out.println("static block"); }
{ System.out.println("instance block"); }
Demo() { System.out.println("constructor"); }
}
// new Demo(); twice prints:
// static block (once)
// instance block / constructor (each time)
Inheritance and Polymorphism
Q11. What is inheritance and what types does Java support? Easy
Q12. Why does Java not support multiple inheritance of classes? Medium
Q13. What is the difference between method overloading and method overriding? Medium
class A { void show() { System.out.println("A"); } }
class B extends A {
@Override void show() { System.out.println("B"); } // overriding
void show(int n) { System.out.println("B " + n); } // overloading
}
A ref = new B();
ref.show(); // B (runtime dispatch)
Q14. What is dynamic method dispatch? Medium
Q15. What is the super keyword used for? Easy
Q16. Can you override a static method? Hard
class P { static void m() { System.out.println("P"); } }
class C extends P { static void m() { System.out.println("C"); } }
P ref = new C();
ref.m(); // P (static = no runtime dispatch)
Q17. Can you override a private method? Medium
Q18. What happens if you override a method and change only the return type? Hard
class Shape {}
class Circle extends Shape {}
class A { Shape make() { return new Shape(); } }
class B extends A { @Override Circle make() { return new Circle(); } } // covariant, OK
Q19. What is the difference between IS-A and HAS-A relationships? Medium
Q20. What is upcasting and downcasting? Medium
Animal a = new Dog(); // upcast, implicit
if (a instanceof Dog d) { // pattern match, Java 16+
d.bark(); // safe downcast
}
Abstraction and Interfaces
Q21. What is abstraction and how is it achieved in Java? Easy
Q22. What is the difference between an abstract class and an interface? Medium
| Aspect | Abstract class | Interface |
|---|---|---|
| Instantiation | Cannot be instantiated | Cannot be instantiated |
| Methods | Abstract plus concrete | Abstract, default, static, private (Java 9+) |
| Fields | Any, including mutable state | public static final constants only |
| Inheritance | A class extends one | A class implements many |
| Constructor | Has constructors | No constructors |
| Use when | Related classes share state and code | Unrelated classes share a capability |
Q23. Can an interface have a constructor? Medium
Q24. What are default methods and why were they added? Medium
interface Greeter {
String name();
default void hello() { System.out.println("Hi " + name()); }
}
Q25. What happens with the diamond problem for default methods? Hard
interface A { default void run() { System.out.println("A"); } }
interface B { default void run() { System.out.println("B"); } }
class C implements A, B {
@Override public void run() { A.super.run(); } // explicit resolution
}
Q26. Can an abstract class have a constructor and a main method? Medium
Q27. What is a functional interface? Medium
Advanced and Tricky
Q28. What is the difference between association, aggregation, and composition? Hard
Q29. What is the Liskov Substitution Principle? Hard
Q30. Why are equals() and hashCode() always overridden together? Hard
record User(int id, String name) {} // equals + hashCode auto-generated
Q31. What is the difference between shallow copy and deep copy? Hard
Q32. What is polymorphism's benefit in real design? Medium
Predict the Output
Snippet 1
class A {
A() { System.out.println("A ctor"); print(); }
void print() { System.out.println("A print"); }
}
class B extends A {
int x = 10;
@Override void print() { System.out.println("B print x=" + x); }
}
new B();
Output:
A ctor
B print x=0
Why: The superclass constructor runs before B's field initialiser. The overridden print() is dispatched to B, but x is still 0 because its initialiser has not executed yet. This partial-construction gotcha is a favourite advanced question.
Snippet 2
class Parent { static String who() { return "Parent"; } }
class Child extends Parent { static String who() { return "Child"; } }
Parent p = new Child();
System.out.println(p.who());
Output:
Parent
Why: Static methods are not polymorphic. p has static type Parent, so Parent.who() is bound at compile time regardless of the runtime object.
Snippet 3
class Box {
int val = 5;
Box add() { val++; return this; }
}
Box b = new Box();
System.out.println(b.add().add().add().val);
Output:
8
Why: Each add() returns this, enabling method chaining. val increments three times from 5 to 8. This pattern is the basis of fluent builders.
Quick Revision Table
| Concept | One-line takeaway |
|---|---|
| Overloading vs overriding | Compile-time vs runtime resolution |
| Static method override | Not possible, only hidden |
| Multiple inheritance | Classes no, interfaces yes |
| Abstract class vs interface | Shared state and code vs pure capability |
| equals + hashCode | Always override together |
| Upcast vs downcast | Implicit safe vs explicit risky |
| Composition vs inheritance | Prefer HAS-A for flexibility |
Frequently Asked Questions
Which OOP topic is asked most in Java interviews in 2026?
Candidates consistently report runtime versus compile-time polymorphism, the difference between abstract class and interface after Java 8 default methods, and why Java has no multiple inheritance of classes. Master those three and you cover most fresher OOP rounds.
Do I need to memorise the four pillars of OOP for Java rounds?
You need to explain each pillar with a Java example, not just name them. Interviewers usually follow up with code, for example asking you to show encapsulation with a private field plus a getter, or polymorphism with an overridden method.
Is method overloading runtime or compile-time in Java?
Overloading is resolved at compile time based on the static type of the arguments. Overriding is resolved at runtime based on the actual object. Mixing these up is the single most common OOP mistake candidates report.
How deep should my answer on inheritance go for a fresher round?
Cover the types Java supports, why multiple inheritance of classes is banned, and the IS-A versus HAS-A trade-off. If you can also state that composition is usually preferred over deep inheritance, you signal design maturity that most freshers miss.
Are records replacing the need to understand equals and hashCode?
Records generate equals, hashCode, and toString for you, but interviewers still ask you to explain the contract. Knowing why equal objects must share a hash code is what they are testing, the record is just a convenience.
Related Articles
- Java Interview Questions 2026, the master 50-question set
- Java Collections Interview Questions 2026, List, Set and Map deep dive
- Java Multithreading Interview Questions 2026, concurrency rounds explained
- TCS Placement Papers 2026, Java OOP features heavily in TCS NQT
Confirm any version-specific Java behaviour on the official Oracle documentation before your interview. This guide reflects candidate-reported question patterns and public preparation resources as of June 2026.
Methodology applied to this articlelast verified 8 Jun 2026
- No fabricated salary numbers or success rates. If we quote a range, it's sourced.
- No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
- No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Explore this topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →Related Articles
Airbnb Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airbnb's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Airtel Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airtel's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
AMD Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing AMD's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Atlassian Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Atlassian's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical,...
Barclays Interview Questions 2026
_Last verified by [Aditya Sharma](/author/aditya-sharma/) · cross-checked against PapersAdda Hiring Pulse and...
More from PapersAdda
Accenture Interview Process 2026: Rounds & Prep
Accenture Interview Questions 2026 (with Answers for Freshers)
Adobe Interview Process 2026: Rounds, OA & Aptitude
Amazon Interview Process 2026: Full Loop + Bar Raiser