Answers Latest Update Graded A+
What is the purpose of the `final` keyword in Java?
✔✔ The `final` keyword is used to declare constants, prevent method overriding, and restrict
inheritance.
Can a Java class inherit multiple classes?
✔✔ No, Java does not support multiple inheritance with classes to avoid ambiguity, but it allows
multiple interface implementations.
How do you create an infinite loop in Java?
✔✔ By using `while(true) { }` or `for(;;) { }`, the loop runs indefinitely unless broken with
`break` or `return`.
What happens if the `main` method is declared as private?
✔✔ The program will compile but will not execute, resulting in a runtime error.
Can a constructor be marked as `static` in Java?
1
,✔✔ No, constructors cannot be `static` because they belong to the instance, not the class.
How does Java achieve platform independence?
✔✔ Java compiles code into bytecode, which runs on the Java Virtual Machine (JVM) instead of
directly on an operating system.
What is the difference between `==` and `.equals()` in Java?
✔✔ `==` compares memory references, while `.equals()` compares object values if properly
overridden.
Can a Java interface have constructors?
✔✔ No, interfaces cannot have constructors because they cannot be instantiated directly.
What is method overloading in Java?
✔✔ Method overloading is defining multiple methods with the same name but different
parameters within the same class.
What will happen if you call `System.exit(0)` in Java?
2
, ✔✔ It will terminate the Java Virtual Machine (JVM) immediately.
Can a class be both `final` and `abstract` in Java?
✔✔ No, because `final` prevents inheritance, while `abstract` requires subclassing to provide
implementations.
How can you make an object immutable in Java?
✔✔ Declare the class as `final`, make all fields `private` and `final`, and provide no setters.
Can a `static` method access instance variables?
✔✔ No, `static` methods belong to the class and cannot access instance variables directly.
What is a marker interface in Java?
✔✔ A marker interface is an interface with no methods, used to signal behavior to the JVM,
such as `Serializable`.
How does Java handle memory management?
3