Constructor chaining, static members, subtype relationships, and reference types using Java SE 25 rules.
Answer: No. Constructors are not members and are not inherited. A subclass has its own constructors, which invoke an appropriate superclass constructor as part of ordinary construction.
Do not infer that every other declaration is inherited: private members, package access across packages, and other inheritance rules impose restrictions. Calling a parent constructor is constructor chaining, not inheriting that constructor.
Answer: No, not even void. A constructor uses the class's simple name without a return type. A same-named declaration with a return type is a method.
The class-instance creation expression produces the new reference. A constructor can complete normally or throw an exception, but cannot return an expression as its result.
Answer: No. Only the constructors selected by the actual chaining path execute. A this invocation selects another constructor in the same class, while super selects a constructor in the direct superclass. Ordinary successful construction eventually reaches Object.
Unused overloads do not run. Chaining initializes one object, including its inherited state, rather than constructing a separate object at every superclass level. Abrupt completion can prevent later initialization steps.
Answer: Use an explicit this(arguments) constructor invocation. It delegates initialization and can consolidate common work. The invocation chain must not form a recursive cycle.
public class ConstructorRoute {
static class Animal {
Animal(String name) { System.out.println("Animal: " + name); }
}
static class Mammal extends Animal {
Mammal(String name) { this(name, 0); }
Mammal(String name, int age) {
super(name);
System.out.println("Age: " + age);
}
}
public static void main(String[] args) {
new Mammal("Lion");
}
}
This prints Animal: Lion and Age: 0. Both Mammal constructors participate in this path; adding another unused overload would not make it execute.
Answer: No. Java SE 25 permits restricted statements before an explicit constructor invocation, for example argument validation. Early construction rules restrict use of the object being initialized.
A constructor body can contain at most one explicit constructor invocation, either this or super. An ordinary constructor with neither implicitly invokes super(), except Object's constructor. Records and other specialized class forms have additional rules.
Answer: A class variable is a static field. Its variable belongs to a class identity rather than to each individual object. Class identity includes the defining class loader.
A static reference can point to a mutable shared object. Static alone provides neither immutability nor thread safety; concurrent updates need an appropriate synchronization policy.
Answer: Prefer the declaring type's name and the dot operator, such as Integer.MAX_VALUE. A static import is another option when it makes the code clearer.
Access control still applies. Calling a static class method through an instance expression does not make it dynamically dispatched and can obscure its class-level nature.
Answer: Class inheritance uses extends, class-to-interface conformance uses implements, and interface inheritance also uses extends. These establish subtype relationships, not just code-sharing arrangements.
A Dog can be an Animal, and a class implementing Runnable is a Runnable. Similar method names alone do not establish the declared relationship. A subtype must also respect the supertype's behavioral contract.
Answer: No. Its compile-time type is fixed, including when inferred with var. It may hold different compatible reference values over time unless reassignment is restricted, for example by final.
A superclass variable can refer to subclass objects or null. Reassigning the variable does not transform the previous object. Generic constraints and ordinary assignment rules still apply.
Answer: No. Constructors are not inherited methods and cannot be overridden. They can be overloaded with distinct parameter signatures.
Constructor selection occurs through compile-time overload rules. Virtual dispatch applies to eligible instance methods, not to choosing a more-derived constructor at runtime.
References: JLS: classes and constructors, JLS: types, and Flexible constructor bodies.