About Question enthuware.ocajp.i.v7.2.1102 :
Posted: Sat Sep 24, 2016 2:11 pm
Hello, I don't think this question is fully correct.
Under what situations does a class get a default constructor?
I selected None of the above, because if a class extends another class without a no-args constructor, it does not get the default constructor.
In this code snippet, SubApp does not define any constructors explicitly, but also does not seem to get the default constructor because App lacks a no-args constructor.
Have I misunderstood the question?
Under what situations does a class get a default constructor?
- All classes in Java get a default constructor.
- You have to define at least one constructor to get the default constructor.
- If the class does not define any constructors explicitly.
- All classes get default constructor from Object class.
- None of the above.
I selected None of the above, because if a class extends another class without a no-args constructor, it does not get the default constructor.
Code: Select all
public class App {
public App(int i) {
}
class SubApp extends App (){
}
}
Have I misunderstood the question?