Course contents

Core Java & OOP: complete interview question bank

Premium45 questions · 35 what-if follow-ups

This is the Core Java pass I would do before a serious backend interview. It collects the OOP and language questions that sound small in the room but reveal whether you understand construction, dispatch, equality, immutability, records, lambdas and modern pattern matching.

Use it like a mock interview. Read the question, say your answer out loud first, then open the model answer and check whether you led with the rule, the trade-off and the edge case.

Treat this as the final pass after the topic pages: classes and objects, inheritance and polymorphism, abstract classes and interfaces, object relationships, keywords, the Object contract, records, enums and Optional, functional basics, modern syntax and reflection and annotations.

Classes & objects

5 questions

Classes, concrete classes, constructors, object creation, this and access rules: the mechanics behind every object you allocate.

Question 1. ConceptWarm-upAsked very often

What is the difference between a class and an object?

Tests class, object, state, behaviour

Show answerHide answer1 follow-up

Model answer

A class is the type definition: fields, methods, constructors and rules. An object is one runtime instance of that class, with its own field values and identity.

A concrete class is instantiable. An abstract class can share state and code but leaves at least part of the contract unfinished.

How I’d say it in the interview

"A class is the blueprint and the object is the house built from it. The methods are shared behaviour, but each object has its own state and identity."

Signals depth

Mentioning that two objects can be equal by value and still be different identities.

Red flags

Calling a class an object, or saying every class must be instantiated.

Follow-ups interviewers ask next

  1. What if a class has only static methods?

    Then you can use it as a utility holder, but it is still a class. Make the constructor private so callers do not create meaningless instances.

Question 2. What does it print?Warm-upCommonly asked

What does this constructor code print?

Tests this constructor call, constructor order

Show answerHide answer1 follow-up

Model answer

class Invoice {
    int total;
    Invoice() { this(100); System.out.print("A " + total + " "); }
    Invoice(int total) { this.total = total; System.out.print("B " + total + " "); }
}
new Invoice();
// prints: B 100 A 100

this(100) must be the first statement. It runs the other constructor, sets total, prints B 100, then control returns to the no-arg constructor, which prints A 100.

How I’d say it in the interview

"B 100, then A 100. The constructor chain runs first, and the no-arg body continues after the delegated constructor returns."

Signals depth

Knowing that a constructor can call either this(...) or super(...), not both explicitly.

Red flags

Thinking both constructors create separate objects.

Follow-ups interviewers ask next

  1. What if Invoice(int total) did not assign the field?

    The field would keep its default 0, and the no-arg constructor would print A 0.

Question 3. ConceptCoreCommonly asked

Name four ways an object can be created besides a normal constructor call.

Tests clone, reflection, deserialization, factories

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 4. ConceptWarm-upCommonly asked

What does this mean, and where can you not use it?

Tests this, instance context, static context

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 5. DesignCoreCommonly asked

Which access modifier should you choose by default?

Tests encapsulation, access modifiers, API design

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Inheritance & polymorphism

5 questions

Inheritance, super, overload resolution, overriding, hiding and casts: this group tests whether you know compile-time choices from runtime dispatch.

Question 6. ConceptCoreAsked very often

Overloading versus overriding: what is decided at compile time and what is decided at runtime?

Tests overloading, overriding, dynamic dispatch

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 7. What does it print?CoreAsked very often

What does this print?

Tests field hiding, static method hiding, overriding

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 8. ConceptCoreSometimes asked

What is a covariant return type?

Tests overriding, covariant returns, return types

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 9. ConceptCoreCommonly asked

When is a cast checked, and what does instanceof pattern matching buy you?

Tests casting, checkcast, instanceof pattern

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 10. ConceptWarm-upCommonly asked

How does super differ from this?

Tests super, constructors, hidden members

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Abstract classes & interfaces

5 questions

Abstract classes, interfaces, default methods and sealed types: the design choices behind partial implementation and closed contracts.

Question 11. DesignCoreAsked very often

Abstract class or interface: how do you choose?

Tests abstract class, interface, state, contract

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 12. ConceptCoreAsked very often

Can an interface have static, default and private methods?

Tests interface methods, Java 8, Java 9

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 13. What does it print?CoreCommonly asked

What happens if two interfaces provide the same default method?

Tests default method diamond, Interface.super

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 14. DesignSeniorCommonly asked

How do sealed classes change interface design?

Tests sealed types, permits, exhaustive switch

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 15. ConceptWarm-upSometimes asked

Why are abstract final and abstract private illegal combinations?

Tests abstract, final, private, static

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Object relationships

4 questions

Is-a, has-a, association, aggregation and composition: this is where OOP becomes design, not syntax.

Question 16. DesignCoreAsked very often

Is-a or has-a: how do you decide?

Tests inheritance, composition, LSP

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 17. ConceptWarm-upCommonly asked

What do association, aggregation and composition mean in code?

Tests association, aggregation, composition

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 18. What does it print?CoreCommonly asked

What does this print, and what is the design bug?

Tests aggregation, defensive copy, aliasing

Model answer, how to say it: unlock with the Java Pass

Question 19. DesignCoreCommonly asked

When is inheritance the right design?

Tests inheritance, template method, framework design

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

static, final & transient

4 questions

static, final and transient show up in small interview snippets because they change lifetime, binding and persistence.

Question 20. What does it print?CoreCommonly asked

What does this static initialization code print?

Tests static initialization, superclass first, source order

Model answer, how to say it: unlock with the Java Pass

Question 21. ConceptCoreCommonly asked

What is a static nested class, and does it have access to this?

Tests static nested class, inner class, this

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 22. ConceptCoreAsked very often

What does final guarantee for fields, methods and classes?

Tests final fields, final methods, final classes

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 23. ConceptCoreCommonly asked

What does transient skip, and when is that useful?

Tests transient, serialization, derived state

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

The Object contract

5 questions

Identity, equality, hashing, ordering, copying and immutability: these rules decide whether your objects behave inside collections.

Question 24. ConceptWarm-upAsked very often

== or equals: what is the rule?

Tests identity, equals, references

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 25. ConceptCoreAsked very often

What is the equals and hashCode contract?

Tests equals, hashCode, HashMap

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 26. What does it print?CoreCommonly asked

What does this map code print?

Tests mutable key, HashMap, hashCode stability

Model answer, how to say it: unlock with the Java Pass

Question 27. DesignCoreAsked very often

Comparable or Comparator: when do you use each?

Tests Comparable, Comparator, natural order

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 28. ConceptCoreCommonly asked

Shallow copy, deep copy and immutability: how do they relate?

Tests shallow copy, deep copy, immutability

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Records, enums & Optional

5 questions

Records, enums and Optional are small APIs with strong opinions. Interviewers use them to test whether you know the generated code and the misuse cases.

Question 29. ConceptCoreAsked very often

What does a record generate, and what can it not do?

Tests records, generated members, restrictions

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 30. What does it print?CoreSometimes asked

What does this compact constructor print?

Tests compact constructor, record normalization

Model answer, how to say it: unlock with the Java Pass

Question 31. ConceptCoreAsked very often

Why is an enum a safe singleton?

Tests enum singleton, serialization, reflection

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 32. What does it print?CoreCommonly asked

What does this enum code print?

Tests enum abstract methods, EnumMap

Model answer, how to say it: unlock with the Java Pass

Question 33. DesignCoreCommonly asked

Where should Optional not be used?

Tests Optional, API design, misuse

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Functional basics

4 questions

Functional interfaces, lambdas, method references and callbacks: enough functional style to write clear Java without pretending Java is Haskell.

Question 34. ConceptWarm-upAsked very often

What is a functional interface?

Tests functional interface, SAM, Object methods

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 35. What does it print?CoreCommonly asked

What does this lambda code print?

Tests lambda this, anonymous class this

Model answer, how to say it: unlock with the Java Pass

Question 36. ConceptCoreCommonly asked

How do method references map to lambdas?

Tests method references, lambdas, target type

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 37. ScenarioCoreSometimes asked

What can go wrong with callbacks?

Tests callbacks, threads, errors, leaks

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Modern syntax

4 questions

Pattern matching, sealed exhaustiveness, record patterns and compact source files: Java 21 has modern syntax, with a few version lines you should say accurately.

Question 38. What does it print?SeniorCommonly asked

What does this pattern switch print?

Tests pattern matching switch, guards, record patterns

Model answer, how to say it: unlock with the Java Pass

Question 39. ConceptCoreSometimes asked

How does switch handle null in Java 21?

Tests switch null, case null, MatchException

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 40. ConceptSeniorCommonly asked

What makes a pattern switch exhaustive?

Tests exhaustiveness, sealed types, enums

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 41. ConceptCoreSometimes asked

What is the Java 21 status of instance main methods and compact source files?

Tests instance main, compact source files, preview, Java 25

Model answer, how to say it: unlock with the Java Pass

Reflection & annotations

4 questions

Reflection and annotations power frameworks, but modern Java makes access, retention and cost worth discussing precisely.

Question 42. ScenarioCoreCommonly asked

What are the costs and risks of reflection?

Tests reflection, performance, safety

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 43. DebuggingSeniorSometimes asked

What changed with setAccessible(true) on modern Java?

Tests strong encapsulation, modules, setAccessible

Model answer, how to say it: unlock with the Java Pass

Question 44. ConceptCoreSometimes asked

What do annotation retention policies mean?

Tests annotations, retention, reflection

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 45. What does it print?CoreSometimes asked

What does this annotation code print?

Tests annotation retention, reflection

Model answer, how to say it: unlock with the Java Pass

Premium question set

Keep reading with the Java Pass

The rest of this question set is part of Java One-Stop Interview Prep: in-depth explanations, diagrams, model answers and how to say them in the interview.

From ₹199 · one-time payment · No auto-renewal

Topic question sets in Core Java & OOP