All 58 questions
What is polymorphism in Java?
Asked in 7 of 158 interviews · last asked Oct 22 · Concept · Junior
Show answer
Polymorphism lets the same operation work with different types. In Java, method overriding provides runtime polymorphism: the actual object's class determines which implementation runs. Method overloading provides compile-time polymorphism: the compiler chooses a method using the declared argument types.
- Overriding works through inheritance or interfaces.
- Overloading uses the same method name with different parameter lists.
- Static methods are hidden, not overridden.
- A broader classification names four types: subtype polymorphism, overloading, parametric polymorphism (generics), and coercion (implicit conversions).
Codeclass Demo { interface Animal { void speak(); } static class Dog implements Animal { public void speak() { System.out.println("Woof"); } } public static void main(String[] args) { Animal animal = new Dog(); animal.speak(); // Runs Dog's implementation } }What the interviewer checks: The interviewer checks whether you understand shared types and can distinguish compile-time method selection from runtime method dispatch.
Other ways it was asked
- “What is polymorphism, and what are two ways to implement it in Java?”
- “What is polymorphism in Java, and how does it work?”
- “What is polymorphism, and how is it expressed in Java?”
What is the equals and hashCode contract, and what breaks in HashMap if you violate it?
Asked in 6 of 158 interviews · last asked Oct 17 · Concept · Mid-level
Show answer
Objects that are equal by equals must have the same hashCode. If equal keys have different hashes, HashMap may fail to find or remove an entry, or store separate entries for keys that should be equal. Overriding equals without a matching hashCode can cause this bug.
- equals must be reflexive, symmetric, transitive, consistent, and return false for null.
- Unequal objects can have the same hashCode; HashMap uses equals to distinguish them.
- During one execution, hashCode must stay consistent while fields used by equals are unchanged.
- Do not change fields used by equals or hashCode while a key is in the map.
What the interviewer checks: The interviewer checks whether you understand equality rules and how broken or mutable keys affect HashMap lookups.
Other ways it was asked
- “What are equals and hashCode in Java?”
- “What are equals and hashCode in Java, and why are both required?”
- “How do equals and hashCode relate in Java, and what specific bug can happen if you override equals but not hashCode for keys in a HashMap?”
How would you design an immutable class in Java?
Asked in 5 of 158 interviews · last asked Oct 6 · Concept · Mid-level
Show answer
An immutable class does not allow its state to change after construction. Make the class final, keep fields private and final, and initialize them in the constructor. Provide no methods that change state, copy mutable inputs, and never expose mutable internal objects through getters.
- A final class prevents subclasses from adding behavior that breaks immutability.
- A final field cannot be reassigned, but its object may still be mutable.
- Use defensive copies for mutable inputs and outputs, including mutable collection elements.
- An unmodifiable collection view alone does not prevent changes through the original collection.
Codeimport java.util.List; // Java 10+: String elements are immutable. public final class Tags { private final List<String> values; public Tags(List<String> values) { this.values = List.copyOf(values); } public List<String> getValues() { return values; } }What the interviewer checks: The interviewer checks whether you can prevent state changes through both methods and shared mutable references.
Other ways it was asked
- “How do you make a class immutable in Java?”
- “Can you explain immutable class design?”
- “What does immutable class design mean in Java?”
What is an interface in Java?
Asked in 5 of 158 interviews · last asked Sep 30 · Concept · Junior
Show answer
An interface in Java is a type that defines a contract for classes to follow. A class uses `implements` and provides the required methods, unless it is abstract. Interfaces let different classes share a common type, so code can use them without depending on a specific implementation.
- A class can implement multiple interfaces.
- Interfaces support polymorphism and make implementations easier to replace or test.
- Interfaces can include abstract methods, default methods, static methods, and constants.
- Default and static methods require Java 8 or later; private interface methods require Java 9 or later.
What the interviewer checks: The interviewer checks whether you understand contracts, implementation, and how interfaces reduce dependencies between classes.
Other ways it was asked
- “What is an interface in Java, and what is it used for?”
- “What advantages do interfaces provide in Java?”
What is inheritance, and what types of inheritance does Java support?
Asked in 4 of 158 interviews · last asked Sep 27 · Concept · Junior
Show answer
Inheritance lets a class reuse and extend another class's fields and methods using `extends`. Java supports single, multilevel, and hierarchical class inheritance. A class can extend only one class, but it can implement multiple interfaces. An interface can also extend multiple interfaces.
- Single: one class directly extends one parent class.
- Multilevel: inheritance forms a chain, such as Animal → Dog → Puppy.
- Hierarchical: several classes extend the same parent class.
- Interfaces support multiple inheritance of type and can be combined with class inheritance.
What the interviewer checks: The interviewer checks whether you understand inheritance patterns and the different rules for classes and interfaces.
Other ways it was asked
- “Which types of inheritance does Java support?”
- “What is inheritance in Java?”
- “How do you achieve inheritance in Java?”
Can a static method be overridden?
Asked in 4 of 158 interviews · last asked Oct 18 · Concept · Junior
Other ways it was asked
- “Can you override a static method in Java?”
- “Can static methods be overridden?”
- “Why can't static methods be overridden in Java?”
Can you explain how Java handles multiple inheritance?
Asked in 4 of 158 interviews · last asked Oct 8 · Concept · Junior
Other ways it was asked
- “How can you implement multiple inheritance in Java?”
- “How can you achieve multiple inheritance in Java when classes do not support it?”
- “Why does Java not allow multiple inheritance?”
What is method overriding in Java?
Asked in 4 of 158 interviews · last asked Jul 16 · Concept · Junior
Other ways it was asked
- “What is method overloading in Java?”
- “How does method overriding work in Java?”
How does the hashCode() method work in Java?
Asked in 3 of 158 interviews · last asked Sep 16 · Concept · Mid-level
Other ways it was asked
- “What does the `hashCode` method do in Java?”
- “How is the hash code calculated in Java?”
- “How does Java calculate the hash code of a String?”
What are the core OOP principles in Java, and how would you apply them in a real example?
Asked in 3 of 158 interviews · last asked Oct 19 · Concept · Junior
Other ways it was asked
- “Could you explain the core principles of object-oriented programming and provide a real-world example of how you have applied them in Java?”
- “Could you explain the four main OOP principles in Java, with a quick example of each?”
- “Can you explain OOP concepts in Java and give a small scenario where they make sense?”
What are the differences between sealed and non-sealed classes in Java?
Asked in 2 of 158 interviews · last asked Sep 2 · Concept · Mid-level
Other ways it was asked
- “What do sealed classes do in Java?”
Why would you choose a Java record over a class?
Asked in 2 of 158 interviews · last asked Sep 22 · Concept · Junior
Other ways it was asked
- “How do Java records differ from standard classes?”
What is reflection in Java?
Asked in 2 of 158 interviews · last asked Apr 23 · Concept · Junior
What are annotations in Java, and what types are there?
Asked in 2 of 158 interviews · last asked Apr 23 · Concept · Junior
What is abstraction in Java?
Asked in 2 of 158 interviews · last asked Sep 9 · Concept · Junior
Other ways it was asked
- “In Java, how do you implement abstraction?”
Can interfaces have static methods in Java?
Asked once · last asked Sep 11 · Concept · Junior
Other ways it was asked
- “Can a functional interface have default and static methods?”
- “Can a functional interface have static methods?”
- “Why can static methods be defined in a Java interface?”
Can you give an example showing when to use an interface versus an abstract class in Java?
Asked once · last asked Sep 27 · Concept · Junior
How do you implement inheritance and composition in Java?
Asked once · last asked Feb 14 · Concept · Mid-level
How can you access an annotation from code and retrieve it programmatically?
Asked once · last asked Mar 4 · Concept · Mid-level
What can an enum contain besides values, and can you add custom methods to it?
Asked once · last asked Mar 4 · Concept · Mid-level
What is the difference between interfaces in Go and interfaces in Java?
Asked once · last asked Jun 9 · Concept · Mid-level
How would you structure Java classes for a management system using object-oriented programming principles?
Asked once · last asked Jun 20 · Scenario · Junior
What access modifiers are available in Java, and how does `protected` differ from package-private access?
Asked once · last asked Jul 22 · Concept · Junior
Can you tell me the difference between an inner class and a subclass?
Asked once · last asked Jul 24 · Concept · Junior
What is the difference between a marker interface and a functional interface?
Asked once · last asked Sep 4 · Concept · Junior
What code changes are required when adding a new method to a Java interface implemented by many classes?
Asked once · last asked Sep 11 · Scenario · Mid-level
Why should fields in an immutable Java class be declared final?
Asked once · last asked Sep 11 · Concept · Mid-level
When should an immutable Java class create copies of objects it returns?
Asked once · last asked Sep 11 · Scenario · Mid-level
How can you optimize a Java singleton implementation so it does not create the object eagerly?
Asked once · last asked Sep 11 · Concept · Mid-level
Other ways it was asked
- “How can you make a Java singleton more efficient without synchronizing the entire method?”
What are the different types of methods in a Java interface?
Asked once · last asked Sep 30 · Concept · Junior
What are the different types of inner classes in Java?
Asked once · last asked Sep 30 · Concept · Junior
What is a constructor in Java, and how is a method different from a constructor?
Asked once · last asked Oct 8 · Concept · Junior
In Java, what are the differences between `==` and `equals()`? And when does `hashCode()` need to be consistent with `equals()`?
Asked once · last asked Oct 23 · Concept · Junior
What are the basic object-oriented programming concepts in Java?
Asked once · last asked Oct 22 · Concept · Junior
What do you find challenging or limiting about Java interfaces?
Asked once · last asked Sep 8 · Concept · Junior
Does a Java constructor return a value?
Asked once · last asked Oct 8 · Concept · Junior
What are annotations, and how do they work?
Asked once · last asked Mar 4 · Concept · Mid-level
What is OOP in Java, and what is encapsulation?
Asked once · last asked Apr 8 · Concept · Junior
What is the this keyword?
Asked once · last asked Apr 8 · Concept · Junior
What are overloaded methods in Java?
Asked once · last asked Apr 23 · Concept · Junior
Can a Java class have a private constructor?
Asked once · last asked Jun 12 · Concept · Junior
How many interfaces can a Java class implement?
Asked once · last asked Jun 15 · Concept · Junior
What is a class in Java? Give an example.
Asked once · last asked Jul 16 · Concept · Junior
Which keyword, `this` or `super`, calls a parent class constructor in Java?
Asked once · last asked Jul 16 · Concept · Junior
Are there any Java classes that do not inherit from Object?
Asked once · last asked Jul 16 · Concept · Junior
Other ways it was asked
- “Which two Java classes do not inherit from `Object`?”
What are getters and setters in Java?
Asked once · last asked Jul 10 · Concept · Junior
Which classes can be extended in Java?
Asked once · last asked Jul 22 · Concept · Junior
Which methods of Java's `Object` class can you name?
Asked once · last asked Jul 22 · Concept · Junior
What is the purpose of the `equals` method in Java?
Asked once · last asked Jul 22 · Concept · Junior
What is the purpose of Lombok's @Data annotation in Java?
Asked once · last asked Sep 4 · Concept · Junior
Other ways it was asked
- “What is the use of @Data?”
How do you create a singleton class in Java?
Asked once · last asked Sep 11 · Concept · Mid-level
Does a singleton class in Java need to be final, and why?
Asked once · last asked Sep 11 · Concept · Mid-level
Other ways it was asked
- “Why do you need to make a singleton class final?”
Can an interface have a constructor in Java?
Asked once · last asked Sep 30 · Concept · Junior
What are nested classes in Java?
Asked once · last asked Sep 30 · Concept · Junior
Other ways it was asked
- “What is the difference between nested and inner classes in Java?”
Can you make a class static in Java?
Asked once · last asked Oct 6 · Concept · Junior
What is a parent class in Java?
Asked once · last asked Oct 10 · Concept · Junior
What is the difference between public and protected in Java?
Asked once · last asked Oct 13 · Concept · Junior
What is the difference between a class and an interface in Java?
Asked once · last asked Oct 21 · Concept · Junior
More Java interview questions
- All Java interview questions
- Java Basics and Strings Interview Questions
- Java Collections and Generics Interview Questions
- Java Multithreading and Concurrency Interview Questions
- Java Backend, Testing and Tools Interview Questions
How this list is made
Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.
Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.
The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every Java interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.
158 interviews, 100 candidates, Sep 2025 to Oct 2026. Updated every month with new interviews.
Or add the Chrome extension