If a class A has non-empty constructor as shown below, class B inherits from A but does not have any constructor. Is that an error condition?
Answered
If a class A has non-empty constructor as shown below, class B inherits from A but does not have any constructor. Is that an error condition?
Best answer
Question:
public class A { public A(int x) { System.out.println("Constructor invoked "+x); } }
Answer:
Yes, this is an error condition. Since constructors are not inherited, results in the below compilation error.
Constructor A in class A cannot be applied to given types;
public class B extends A{ ^
required: int
found: no arguments
reason: actual and formal argument lists differ in length