Review final parameters, method overriding, thread liveness, and the relationship between abstract declarations and concrete implementations.
Answer: None. A local variable cannot be public, protected, or private. Final is legal but is not an access modifier: it prevents reassignment after the variable receives its value.
A final local can be declared before assignment if definite-assignment rules are satisfied. Final does not make a referenced object immutable. An effectively final local is one that is not reassigned even without the keyword, which matters when capturing it in a lambda or local class.
Answer: A final instance method cannot be overridden by a subclass. A final static method cannot be hidden by a subclass declaration with the corresponding signature. Overloading with different parameters remains possible.
Use final when preserving that implementation is part of the extension contract. It does not make the method pure, make fields immutable, or provide synchronization. A private method is already not overridable, and a class declared final cannot be subclassed in the first place.
Answer: It reports whether the thread has started and has not yet terminated. A NEW thread and a TERMINATED thread both return false. A live thread may be blocked or waiting, so alive does not mean currently using a processor.
The result is a snapshot that can change immediately. Use join when the requirement is to wait for termination, rather than repeatedly polling isAlive. A Thread object can remain reachable after its execution has ended; object reachability and thread liveness are different properties.
Answer: The parameter variable cannot be reassigned in the method body. Java passes arguments by value; for an object argument, the copied value is a reference. Final fixes that reference variable, not the referenced object's state.
import java.util.ArrayList;
import java.util.List;
public class FinalParameter {
static void addName(final List<String> names) {
names.add("Ada");
}
public static void main(String[] args) {
List<String> names = new ArrayList<>();
addName(names);
System.out.println(names);
}
}
The output is [Ada]. Reassigning names inside addName would be illegal, but modifying the supplied mutable list is permitted. Final on a parameter is not part of the method signature used for overloading.
Answer: It declares an instance-method contract without providing a body in that declaration. A concrete subclass must supply or inherit an implementation that satisfies the outstanding obligation. Intermediate subclasses can remain abstract.
An abstract method can specify parameters, a return type, visibility, and a throws clause. Those details constrain legal overrides even though the declaration has no executable body. Abstract methods are therefore more than placeholders with no information about required behavior.
Answer: It has no body and ends with a semicolon. In an ordinary class it uses abstract, and the class must be abstract if it has unimplemented abstract obligations. An interface's ordinary abstract method declaration can omit the abstract keyword.
Abstract methods cannot also be private, static, final, native, or synchronized. Those modifiers conflict with the abstract-method rules. A concrete override may be synchronized even though the abstract declaration is not; locking is an implementation decision rather than an inherited method modifier.
Answer: Yes. Abstract can prevent direct instantiation even when every method has an implementation. The class may provide shared state, constructors, utilities, or a base implementation intended only for subclasses.
A subclass does not have to invent an override if there is no outstanding abstract obligation. It can be concrete when the remaining rules permit. Conversely, a class may need to be abstract because of inherited obligations even if it declares no new abstract methods itself.
Answer: With a semicolon, for example public abstract void draw();. An empty pair of braces is a body and is not valid on an abstract method. For an ordinary implemented method, the body replaces the semicolon and abstract is removed.
A semicolon alone is not sufficient to identify abstraction in all contexts: native methods also omit a Java body. Read the modifiers and declaration context. An interface default method, in contrast, must provide a body.
Answer: An abstract class cannot be directly instantiated. A concrete class can be instantiated when an appropriate constructor is accessible and the other creation rules are satisfied. Non-abstract does not imply that every caller can invoke a constructor; constructors can be private.
An expression creating an anonymous subclass of an abstract class creates the concrete anonymous subtype, not a direct instance of the abstract class. Abstract-typed variables can still refer to concrete subclass instances and invoke their implemented behavior polymorphically.
Answer: It can define a common abstraction while sharing implementation, state, and construction logic among subclasses. Abstract methods identify behavior left to concrete subtypes, while concrete methods can implement the shared portion.
A concrete subclass may inherit an implementation from an intermediate superclass rather than declare every method anew. Prefer an interface when the main need is a contract across unrelated classes; use an abstract class when the single-class inheritance relationship and shared implementation fit the design.
References: Method modifiers, Final variables, and Thread.isAlive.