Java Interview QuestionBank
Java Interview QuestionBank
DIFFICULTY LEGEND
SCENARI
Design / real-world application of concepts
O
2 OOP Concepts 50
3 Collections Framework 55
4 Exception Handling 30
5 Multithreading 40
6 Java 8+ Features 50
7 Mixed / Cross-Topic 30
TOTAL 300+
■ SECTION 1 — CORE JAVA FUNDAMENTALS
Q2. What is the difference between JDK, JRE, and JVM? BASIC
Q3. What happens when you run a Java program — explain the full flow from .java to output? MEDIUM
Q4. What is bytecode? Who generates it and who executes it? BASIC
Q5. What is the difference between the Interpreter and the JIT Compiler inside JVM? MEDIUM
Q7. What are the 11 features of Java? Explain any 5 that matter in real projects. MEDIUM
Q9. What does 'Write Once, Run Anywhere' really mean in a CI/CD deployment context? SCENARIO
Q10. What is the difference between Java being compiled and interpreted? MEDIUM
Q11. Explain all 5 memory areas of JVM with what is stored in each. MEDIUM
Q12. What is the difference between Stack memory and Heap memory? BASIC
Q14. Where are local variables stored? Where are objects stored? BASIC
Q15. What is Metaspace in Java 8+? How is it different from PermGen? MEDIUM
Q16. What is Garbage Collection? How does it decide which objects to collect? BASIC
Q17. What are the different types of GC algorithms — Serial, Parallel, CMS, G1, ZGC? MEDIUM
Q19. What is the difference between Young Generation, Old Generation? MEDIUM
Q20. When does OutOfMemoryError occur? What JVM flag do you adjust? MEDIUM
Q23. What is finalize() method? Why was it deprecated in Java 9+? TRICKY
Q24. What are strong, soft, weak, and phantom references in Java? TRICKY
Q25. If an object has a circular reference, will GC collect it? Why? TRICKY
Q26. What are the 8 primitive data types in Java with their sizes? BASIC
Q27. What is the default value of each primitive type and reference type? BASIC
Q28. What is the difference between widening and narrowing type conversion? BASIC
Q29. What is the range of int? What happens when you go beyond it (overflow)? MEDIUM
Q30. Why should you never use float or double for currency/financial calculations? MEDIUM
Q31. What is the difference between prefix (++i) and postfix (i++) operators? MEDIUM
Q33. What are bitwise operators? Where are they used in real backend code? MEDIUM
Q34. What does the >>> (unsigned right shift) operator do differently from >>? TRICKY
Q37. Why are Strings immutable in Java? What are the advantages? MEDIUM
Q38. What is the String Pool (String Intern Pool)? Where does it live in Java 7+ vs earlier? MEDIUM
Q39. What is the difference between String s = 'hello' and new String('hello')? MEDIUM
Q40. What does [Link]() do? When would you use it? TRICKY
Q42. What is autoboxing and unboxing? When can unboxing cause a NullPointerException? MEDIUM
Q43. What is the Integer cache? Which range is cached and what is the trap? TRICKY
Q45. What is the output? Explain the == vs equals() behavior for String and Integer. OUTPUT
Q46. What are the 4 pillars of OOP? Define each in one crisp line. BASIC
Q48. What is the difference between instance variables and local variables? BASIC
Q49. What is the difference between instance methods and static methods? BASIC
Q50. Where would you actually use a static method in a real project? SCENARIO
Q51. What is a static block? When does it run? Can it throw an exception? MEDIUM
Q52. Can a class be both abstract and final? Can a method be both static and abstract? TRICKY
2B. Constructors
Q55. What is a default constructor? When does the compiler NOT generate one? MEDIUM
Q57. What is constructor chaining? Explain this() and super() with rules. MEDIUM
Q58. Can a constructor be private? When would you use a private constructor? TRICKY
Q59. What is a copy constructor? Java doesn't have one built-in — how do you implement it? MEDIUM
Q60. What happens if you call super() explicitly in a child constructor vs not calling it? TRICKY
Q61. Can a constructor return a value? What is its return type? TRICKY
2C. Encapsulation
Q64. Why is it a bad practice to make fields public? Give a real-world consequence. MEDIUM
Q65. What is the JavaBean convention? Why is it important in frameworks like Spring and Hibernate? MEDIUM
Q66. Can you have a getter without a setter? When and why would you do that? SCENARIO
Q67. How would you implement an immutable class in Java? List all the rules. TRICKY
2D. Inheritance
Q70. What are the 5 types of inheritance? Which ones does Java support? MEDIUM
Q71. Why does Java NOT support multiple inheritance with classes? What is the diamond problem? MEDIUM
Q72. How does Java solve the diamond problem using interfaces? TRICKY
Q73. What is the difference between IS-A and HAS-A relationships? MEDIUM
Q75. What is method hiding? How is it different from method overriding? TRICKY
Q76. Can a subclass constructor call a superclass constructor? What are the rules? MEDIUM
Q77. What does the 'final' keyword do to a class, method, and variable? MEDIUM
Q80. What is polymorphism? What are its two types in Java? BASIC
Q81. What is method overloading? What can differ between overloaded methods? BASIC
Q82. Can you overload a method based only on the return type? Why or why not? TRICKY
Q83. What is method overriding? What are the exact rules for valid overriding? MEDIUM
Q84. What is the @Override annotation? Why should you always use it? MEDIUM
Q86. What is covariant return type? In which Java version was it introduced? TRICKY
Q88. What is the difference between static binding (compile-time) and dynamic binding (runtime)? MEDIUM
Q89. If a parent class method throws IOException, can the overriding child method throw Exception? Why? TRICKY
class Animal { void sound() { [Link]("Animal sound"); } } class Dog extends Animal {
void sound() { [Link]("Dog barks"); } } public class Test { public static void
main(String[] args) { Animal a = new Dog(); [Link](); } }
class Test { static void print(int x) { [Link]("int: " + x); } static void print(long
x) { [Link]("long: " + x); } static void print(double x) {
[Link]("double: " + x); } public static void main(String[] args) { print(10);
print(10L); print(10.0); byte b = 5; print(b); } }
Q93. What is an abstract class? Can it have constructors? Can it have concrete methods? BASIC
Q94. What is an interface? What can and cannot it contain (before Java 8)? BASIC
Q95. What changed in interfaces with Java 8 (default and static methods)? MEDIUM
Q96. What changed with interfaces in Java 9 (private methods in interfaces)? TRICKY
Q97. What is the difference between an abstract class and an interface — detailed comparison? MEDIUM
Q98. Can you instantiate an abstract class? Can you instantiate an interface? BASIC
Q99. When would you choose an abstract class over an interface in real project design? SCENARIO
Q10 What is a marker interface? Give two examples from the JDK. MEDIUM
0.
1.
Q10 Can an interface extend another interface? Can it extend multiple interfaces? TRICKY
2.
Q10 What happens if a class implements two interfaces that have a default method with the same TRICKY
3. signature?
Q10 Where do you use abstraction in your real projects? Give a concrete example. SCENARIO
4.
Q10 Design a notification system using abstract class and interface. Which would you use and why? SCENARIO
5.
6.
7.
Q10 What is the difference between this() and super() and what is the constraint on their placement? MEDIUM
8.
9.
0.
Q11 How do you safely downcast? What operator do you use? BASIC
1.
Q11 What is pattern matching instanceof (Java 16+)? How does it improve downcasting? TRICKY
2.
Q11 Can you use 'this' inside a static method? Why? MEDIUM
3.
4.
Q11 What is the Java Collections Framework (JCF)? What problem does it solve? BASIC
5.
Q11 Draw/describe the hierarchy: Iterable → Collection → List / Set / Queue. Where does Map fit? MEDIUM
6.
Q11 What is the difference between Collection (interface) and Collections (utility class)? MEDIUM
7.
Q11 What is the difference between Arrays and Collections? When would you choose one over the other? MEDIUM
8.
Q11 What are the key differences between List, Set, and Map interfaces? BASIC
9.
Q12 What is the difference between synchronized collections and concurrent collections? MEDIUM
0.
1.
Q12 What is the default capacity of ArrayList? How does it grow when full? MEDIUM
2.
Q12 What is the time complexity of get(), add(), add(index), remove(index) for ArrayList? MEDIUM
3.
Q12 What is LinkedList? How does it store elements internally (doubly-linked)? BASIC
4.
Q12 Compare ArrayList vs LinkedList for: random access, insertion in middle, memory usage. MEDIUM
5.
Q12 When should you NEVER use LinkedList? When is it better than ArrayList? SCENARIO
6.
7.
8.
Q12 How do you make an ArrayList thread-safe? What are the options? MEDIUM
9.
0.
Q13 What happens when you run this code? Why? OUTPUT
1.
Q13 What guarantees does a Set provide? How is it different from a List? BASIC
2.
3.
4.
Q13 What happens if you add an object to a HashSet without overriding hashCode() and equals()? TRICKY
5.
6.
Q13 What is TreeSet? What ordering does it use? What interface must elements implement? MEDIUM
7.
Q13 Compare HashSet vs LinkedHashSet vs TreeSet for: ordering, performance, null handling. MEDIUM
8.
Q13 Can HashSet store null? Can TreeSet store null? Why the difference? TRICKY
9.
Q14 What is NavigableSet? Name 4 methods that TreeSet provides through NavigableSet. TRICKY
0.
Q14 What is HashMap? What data structure does it use internally? BASIC
1.
2.
Q14 What is hashing? What is a hash collision? How does HashMap handle it? MEDIUM
3.
Q14 What changed in Java 8 with HashMap's collision handling (treeification)? MEDIUM
4.
Q14 What is the default initial capacity and load factor of HashMap? When does it resize? MEDIUM
5.
Q14 What is rehashing? Why is it expensive? How do you avoid it? TRICKY
6.
Q14 What is the contract between hashCode() and equals()? What happens if you violate it? TRICKY
7.
Q14 Can HashMap have duplicate keys? Can it have duplicate values? Can it have a null key? MEDIUM
8.
Q14 What is the difference between HashMap, Hashtable, LinkedHashMap, and TreeMap? MEDIUM
9.
0.
Q15 How does ConcurrentHashMap achieve thread safety without locking the entire map? TRICKY
1.
Q15 What is getOrDefault()? What is computeIfAbsent()? When do you use each? MEDIUM
2.
3.
Q15 How would you implement an LRU cache using LinkedHashMap? SCENARIO
4.
Q15 You have 1 million records to store in a HashMap — what initial capacity should you set and why? SCENARIO
5.
Q15 What is the output? (HashMap key mutation — the broken contract) OUTPUT
6.
Q15 What is a Queue? What are the two sets of Queue methods and how do they differ in failure behavior? MEDIUM
7.
Q15 What is the difference between offer(), add(), poll(), remove(), peek(), element()? MEDIUM
8.
Q15 What is ArrayDeque? Why is it preferred over LinkedList for Queue/Stack use cases? MEDIUM
9.
0.
1.
Q16 Why is the Stack class considered legacy? What should you use instead? MEDIUM
2.
Q16 What is BlockingQueue? Name two implementations and when to use them. TRICKY
3.
Q16 Design an order processing system using a PriorityQueue where premium orders are processed first. SCENARIO
4.
5.
6.
Q16 What is the difference between fail-fast and fail-safe iterators? Give one example of each. MEDIUM
7.
Q16 Why does ConcurrentModificationException occur and how do you avoid it? MEDIUM
8.
Q16 How do you safely remove elements from a collection while iterating? MEDIUM
9.
Q17 What is the difference between Comparable and Comparator? MEDIUM
0.
Q17 Which package does Comparable belong to? Which does Comparator belong to? BASIC
1.
Q17 What does compareTo() return — explain negative, zero, positive values. MEDIUM
2.
Q17 How do you sort a list by multiple fields using [Link]().thenComparing()? MEDIUM
3.
Q17 Can you pass a null-safe Comparator? What is [Link]() / nullsLast()? TRICKY
4.
5.
Q17 What is the Throwable hierarchy — draw it: Throwable → Error / Exception. BASIC
6.
7.
Q17 What is the difference between checked and unchecked exceptions? BASIC
8.
Q17 Give 5 examples of checked exceptions and 5 examples of unchecked exceptions. BASIC
9.
0.
Q18 What are common JVM Errors — StackOverflowError, OutOfMemoryError, ExceptionInInitializerError? MEDIUM
1.
Q18 Can you catch an Error? Should you? When might you? TRICKY
2.
3.
Q18 What is the execution order of try, catch, and finally blocks? BASIC
4.
Q18 Does finally always execute? Name the two scenarios where it does NOT. MEDIUM
5.
Q18 What happens if both the try block and the finally block throw an exception? TRICKY
6.
Q18 Can a finally block override a return value from a try block? Is this good practice? TRICKY
7.
Q18 What is multi-catch (catch multiple exception types in one block)? What Java version introduced it? MEDIUM
8.
Q18 What is try-with-resources? What interface must the resource implement? MEDIUM
9.
Q19 What is the closing order of resources in try-with-resources with multiple resources? TRICKY
0.
Q19 What is suppressed exception in try-with-resources? How do you access it? TRICKY
1.
Q19 What is exception chaining / wrapping? Why is it important for debugging? MEDIUM
2.
3.
public static int test() { try { [Link]("try"); return 1; } catch (Exception e) {
[Link]("catch"); return 2; } finally { [Link]("finally"); return 3; //
<-- overrides try's return! } } [Link](test());
4.
5.
Q19 When do you use throws on a method signature vs try-catch inside the method? MEDIUM
6.
Q19 How do you create a custom exception? When should it extend Exception vs RuntimeException? MEDIUM
7.
Q19 Why should custom exceptions in REST APIs typically be unchecked (RuntimeException)? SCENARIO
8.
Q19 What is the best practice for exception messages in a production microservice? SCENARIO
9.
Q20 What is the difference between re-throwing an exception and wrapping it? MEDIUM
0.
Q20 Your REST API throws a generic Exception up the call stack. What are the problems with this design? SCENARIO
1.
Q20 How does Spring's @ControllerAdvice + @ExceptionHandler pattern work to handle custom SCENARIO
2. exceptions?
Q20 Can you throw a checked exception from a lambda expression? Why is this a problem? TRICKY
3.
4.
Q20 In a multi-catch block, can the caught types be in an inheritance relationship? TRICKY
5.
■ SECTION 5 — MULTITHREADING
6.
Q20 What are the two ways to create a thread in Java? Which is preferred and why? BASIC
7.
Q20 What is Runnable vs Callable? What is the key difference in their return type? MEDIUM
8.
Q20 What are all 6 states of a Thread lifecycle? Draw/describe the transitions. MEDIUM
9.
Q21 What is the difference between start() and run() methods? What happens if you call run() directly? MEDIUM
0.
1.
Q21 What is a daemon thread? How do you mark a thread as daemon? MEDIUM
2.
Q21 What is the difference between user threads and daemon threads at JVM shutdown? TRICKY
3.
Q21 What is thread priority in Java? Does it guarantee execution order? MEDIUM
4.
5.
Q21 What does the synchronized keyword do? What is the lock/monitor it uses? MEDIUM
6.
Q21 What is the difference between synchronized method and synchronized block? Which is better and MEDIUM
7. why?
Q21 What does static synchronized mean? What object does it lock on? TRICKY
8.
Q21 What is the volatile keyword? What problem does it solve? MEDIUM
9.
0.
Q22 What is AtomicInteger? How does it differ from using synchronized for a counter? MEDIUM
1.
Q22 What is the difference between synchronized, volatile, and Atomic classes — when do you use each? TRICKY
2.
3.
Q22 What is a ThreadLocal variable? When would you use it in a web application? TRICKY
4.
Q22 Is this counter implementation thread-safe? What output do you expect from 1000 threads each calling OUTPUT
5. increment()?
class Counter { private int count = 0; public void increment() { count++; } // NOT atomic! public
int getCount() { return count; } } // Expected: 1000 | Actual: often < 1000 — why?
Q22 What is a deadlock? What are the 4 conditions for deadlock to occur? MEDIUM
6.
7.
Q22 What is the difference between wait(), notify(), and notifyAll()? MEDIUM
8.
Q22 Which class do wait(), notify(), and notifyAll() belong to? In which context must they be called? TRICKY
9.
0.
Q23 What is an ExecutorService? Why use it instead of creating Thread objects directly? MEDIUM
1.
2. newSingleThreadExecutor()?
Q23 What is the difference between submit() and execute() in ExecutorService? MEDIUM
3.
Q23 What is a Future? How do you get a result from a Callable via Future? MEDIUM
4.
5.
Q23 What is the difference between shutdown() and shutdownNow() in ExecutorService? MEDIUM
6.
Q23 What is a thread pool? Why does it improve performance over creating a new thread per request? MEDIUM
7.
Q23 Your web server creates a new Thread for every HTTP request. What is the problem with this SCENARIO
8. approach?
9.
0.
1.
2.
Q24 What is a CyclicBarrier? How is it different from CountDownLatch? TRICKY
3.
4.
Q24 What is the ForkJoinPool? What kind of tasks is it designed for? TRICKY
5.
■ SECTION 6 — JAVA 8+ FEATURES
6.
7.
8.
9.
0.
Q25 What is a BiFunction? What is a BinaryOperator? How are they related? MEDIUM
1.
2.
Q25 Compose two Predicates using and(), or(), negate(). Write an example. MEDIUM
3.
Q25 What is a method reference? What are the 4 types of method references? MEDIUM
4.
Q25 When should you use a method reference vs a lambda? Is one always better? MEDIUM
5.
Q25 Can a lambda capture local variables from its enclosing scope? What rule must they follow? TRICKY
6.
Q25 What is the difference between a lambda and an anonymous inner class? TRICKY
7.
8.
9.
int x = 10; Runnable r = () -> [Link](x); [Link](); // Now try: x = 20; -- does it
compile? Why?
Q26 What is the Stream API? What problem does it solve? BASIC
0.
Q26 What is the difference between intermediate and terminal operations? Give 5 examples of each. MEDIUM
1.
Q26 What does it mean that streams are lazy? Prove it with an example. TRICKY
2.
Q26 What is the difference between map() and flatMap()? Give a clear example. MEDIUM
3.
Q26 What is filter()? What type must the predicate return? BASIC
4.
Q26 What is reduce()? What is its identity element? Write an example summing a list. MEDIUM
5.
Q26 What is collect()? What is [Link](), toSet(), toMap(), groupingBy(), joining()? MEDIUM
6.
Q26 What is the difference between findFirst() and findAny()? When does findAny() differ? TRICKY
7.
Q26 What is peek()? When is it useful? Why should you not use it for side effects? TRICKY
8.
Q26 What is distinct()? What does it use internally to determine uniqueness? MEDIUM
9.
Q27 What is the difference between sorted() with no arg vs sorted(Comparator)? MEDIUM
0.
Q27 What is the difference between count(), sum(), average(), min(), max()? MEDIUM
1.
2.
3.
4.
Q27 Can a stream be reused after a terminal operation? What exception do you get? MEDIUM
5.
Q27 What is an IntStream, LongStream, DoubleStream? Why use them over Stream? TRICKY
6.
Q27 When should you NOT use streams? What are their performance trade-offs? TRICKY
7.
Q27 What is the output? (Stream laziness — how many elements are processed?) OUTPUT
8.
Q27 Write a stream pipeline to: given a list of employees, find the top 3 highest-paid employees in the OUTPUT
// Input: List<Employee> where Employee has: name, dept, salary // Expected output: "Alice, Bob,
Charlie" (sorted desc by salary) String result = [Link]() .filter(e ->
"Engineering".equals([Link]()))
.sorted([Link](Employee::getSalary).reversed()) .limit(3)
.map(Employee::getName) .collect([Link](", "));
6C. Parallel Streams
0.
1.
Q28 When does parallel stream actually improve performance? When does it make things worse? TRICKY
2.
Q28 Is parallel stream always faster? What are the hidden costs? TRICKY
3.
Q28 What issues can arise with parallel streams and mutable shared state? TRICKY
4.
5.
6D. Optional
6.
Q28 What is the difference between [Link](), [Link](), and [Link]()? MEDIUM
7.
Q28 What is the difference between orElse() and orElseGet()? When should you prefer orElseGet()? TRICKY
8.
Q28 What does orElseThrow() do? How do you pass a custom exception? MEDIUM
9.
Q29 What is the difference between map() and flatMap() on Optional? TRICKY
0.
Q29 Why should Optional NOT be used as a method parameter or as a field in a class? TRICKY
1.
Q29 What does ifPresent() do? What is ifPresentOrElse() (Java 9)? MEDIUM
2.
Q29 What is [Link]() (Java 9)? How is it different from orElse()? TRICKY
3.
4.
Q29 What are default methods in interfaces? Why were they introduced in Java 8? MEDIUM
5.
Q29 What are static methods in interfaces? When are they useful? MEDIUM
6.
Q29 What is the new Date/Time API ([Link])? What were the problems with the old Date/Calendar? MEDIUM
7.
Q29 What is the difference between LocalDate, LocalDateTime, ZonedDateTime, and Instant? MEDIUM
8.
Q29 What is a DateTimeFormatter? How do you parse and format dates? MEDIUM
9.
Q30 What are the key new features in Java 9, 10, 11? (var, modules, new String methods) MEDIUM
0.
Q30 What is var (Java 10 local variable type inference)? What are its limitations? MEDIUM
1.
Q30 What are records in Java 16+? How are they different from a regular class? TRICKY
2.
Q30 What are sealed classes in Java 17? What problem do they solve? TRICKY
3.
Q30 What is the switch expression (Java 14+)? How is it different from switch statement? TRICKY
4.
5.
■ SECTION 7 — MIXED / CROSS-TOPIC REAL INTERVIEW
QUESTIONS
These questions combine multiple topics and represent the most common real-interview patterns for 1–3 years
experience candidates in India. Strong candidates will connect concepts across sections.
Q30 What happens when two threads concurrently call put() on the same HashMap? What can go wrong? TRICKY
6.
Q30 What is ConcurrentHashMap? How does it avoid the issues of HashMap in multithreaded use? MEDIUM
7.
Q30 Can you use streams with synchronized collections like Vector or [Link]()? TRICKY
8.
Q30 Why is CopyOnWriteArrayList safe for concurrent reads but expensive for writes? TRICKY
9.
Q31 If you use [Link]() and iterate over it, is it thread-safe? Why not? TRICKY
0.
Q31 Why is String immutable — what is the real backend security advantage? SCENARIO
1.
Q31 Why can String be safely used as a HashMap key but mutable objects cannot? TRICKY
2.
Q31 You are building a report that concatenates 10,000 strings in a loop. What do you use and why? SCENARIO
3.
Q31 What is [Link]() and when would you use it for performance optimization? TRICKY
4.
Q31 Why does '+' operator on Strings in a loop create O(n^2) memory — explain with JVM internals. TRICKY
5.
Q31 You are designing a payment service. How would you use abstract class + interface together? SCENARIO
6.
Q31 What is the SOLID principle? Briefly explain each letter with a Java example. SCENARIO
7.
Q31 What design patterns have you used in Java? Explain Singleton, Factory, Strategy with examples. SCENARIO
8.
Q31 How is the Singleton pattern broken by reflection, serialization, or cloning — and how do you fix it? TRICKY
9.
Q32 You have a class hierarchy going 5 levels deep — what problems does this cause and how do you fix SCENARIO
0. it?
Q32 What is the difference between method overloading and operator overloading? Does Java support the MEDIUM
1. latter?
Q32 Why does Java not support operator overloading for custom classes? TRICKY
2.
Q32 How do you remove duplicate elements from a List while preserving insertion order using streams? MEDIUM
3.
Q32 How do you find the frequency of each word in a sentence using streams? MEDIUM
4.
5.
Q32 How do you convert a List to a Map where the value is the string length? MEDIUM
6.
Q32 How do you find the second highest salary from a list of employees using streams? MEDIUM
7.
Q32 What is the difference between stream().collect(toList()) and stream().toList() (Java 16)? TRICKY
8.
Q32 How do you check if all elements, any element, or no element in a list matches a condition? MEDIUM
9.
Q33 How would you group a list of transactions by category and sum amounts per category using streams? SCENARIO
0.
Q33 Your REST API returns a generic 500 error for all exceptions. How do you fix the exception handling SCENARIO
1. architecture?
Q33 What is the best practice for exception logging in a microservice — what information must you always SCENARIO
2. log?
Q33 Should service layer methods throw checked or unchecked exceptions? What are the trade-offs? SCENARIO
3.
Q33 How do you handle NullPointerException defensively — using Optional vs null check vs @NotNull? SCENARIO
4.
Q33 In a try-catch block, you catch Exception. A colleague says you should catch more specific types. Why SCENARIO
6.
class Test { static int x = 10; int y = 20; static { x = 30; [Link]("static block:
x=" + x); } { y = 40; [Link]("instance block: y=" + y); } Test() {
[Link]("constructor: y=" + y); } public static void main(String[] args) {
[Link]("main: x=" + x); Test t1 = new Test(); Test t2 = new Test(); } }
7.
8.
9.
Map<Integer, String> map = new HashMap<>(); [Link](3, "Three"); [Link](1, "One"); [Link](2,
"Two"); for ([Link]<Integer, String> e : [Link]()) [Link]([Link]() + " ->
" + [Link]()); // Is the output order guaranteed? What would LinkedHashMap give?
0.
■ Java Interview Complete Question Bank | 300+ Questions | 0–3 Years Experience | Service-Based & Mid-Level Product Companies | 30%
Basic · 40% Medium · 30% Tricky/Output/Scenario