Core Java & OOP: complete interview question bank
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 questionsClasses, concrete classes, constructors, object creation, this and access rules: the mechanics behind every object you allocate.
What is the difference between a class and an object?
Tests class, object, state, behaviour
Show answerHide answer
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
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.
What does this constructor code print?
Tests this constructor call, constructor order
Show answerHide answer
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
What if
Invoice(int total)did not assign the field?The field would keep its default
0, and the no-arg constructor would printA 0.
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
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
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 questionsInheritance, super, overload resolution, overriding, hiding and casts: this group tests whether you know compile-time choices from runtime dispatch.
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
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
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
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
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 questionsAbstract classes, interfaces, default methods and sealed types: the design choices behind partial implementation and closed contracts.
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
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
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
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
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 questionsIs-a, has-a, association, aggregation and composition: this is where OOP becomes design, not syntax.
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
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
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
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 questionsstatic, final and transient show up in small interview snippets because they change lifetime, binding and persistence.
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
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
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
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 questionsIdentity, equality, hashing, ordering, copying and immutability: these rules decide whether your objects behave inside collections.
== or equals: what is the rule?
Tests identity, equals, references
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
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
What does this map code print?
Tests mutable key, HashMap, hashCode stability
Model answer, how to say it: unlock with the Java Pass
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
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 questionsRecords, enums and Optional are small APIs with strong opinions. Interviewers use them to test whether you know the generated code and the misuse cases.
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
What does this compact constructor print?
Tests compact constructor, record normalization
Model answer, how to say it: unlock with the Java Pass
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
What does this enum code print?
Tests enum abstract methods, EnumMap
Model answer, how to say it: unlock with the Java Pass
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 questionsFunctional interfaces, lambdas, method references and callbacks: enough functional style to write clear Java without pretending Java is Haskell.
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
What does this lambda code print?
Tests lambda this, anonymous class this
Model answer, how to say it: unlock with the Java Pass
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
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 questionsPattern matching, sealed exhaustiveness, record patterns and compact source files: Java 21 has modern syntax, with a few version lines you should say accurately.
What does this pattern switch print?
Tests pattern matching switch, guards, record patterns
Model answer, how to say it: unlock with the Java Pass
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
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
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 questionsReflection and annotations power frameworks, but modern Java makes access, retention and cost worth discussing precisely.
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
What changed with setAccessible(true) on modern Java?
Tests strong encapsulation, modules, setAccessible
Model answer, how to say it: unlock with the Java Pass
What do annotation retention policies mean?
Tests annotations, retention, reflection
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
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
- Classes & objects: interview questions & scenarios
- Inheritance & polymorphism: interview questions & scenarios
- Abstract classes & interfaces: interview questions & scenarios
- Object relationships: interview questions & scenarios
- static, final & transient: interview questions & scenarios
- The Object contract: interview questions & scenarios
- Records, enums & Optional: interview questions & scenarios
- Functional Java basics: interview questions & scenarios
- Modern Java syntax: interview questions & scenarios
- Reflection & annotations: interview questions & scenarios
- Strings in depth: interview questions & scenarios
- Exceptions: interview questions & scenarios
- Nested types: interview questions & scenarios