Can a class inherit the constructors of its superclass?
Answer Posted / qim2010
No. A class cannot inherit constructor of its superclass but
can call the superclass constructor. If a class called
“SpecialPet” extends your “Pet” class then you can use the
keyword “super” to invoke the superclass’s constructor. E.g.
public SpecialPet(int id) {
super(id); //must be the very first statement in the
constructor.
}
To call a regular method in the super class use:
“super.myMethod( );”. This can be called at any line
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
How do constructors use this() and super()?
Does constructor be static?
Differentiate storage classes on the basis of their scope?
What do you mean by of string::valueof expression in java 8?
What is a top level class in java?
What is nullpointerexception in java?
What is the java idl system?
What is the meaning of nullable?
Explain about narrowing conversion in java?
What is the major difference between linkedlist and arraylist?
How does linkedlist work in java?
What is java reflection?
What is the default execution method in java?
Why arraylist is not synchronized in java example?
What does int [] mean in java?