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
Explain the difference between an Interface and an Abstract class?
How to pass arraylist to stored procedure in java?
What is hashtable and explain features of hashtable?
What is a bubble sort in java?
Explain the difference between abstract classes and interfaces in java?
What are the drawbacks of reflection?
Why java is object oriented?
What is an object in java and how is it created?
What are the differences between stringbuffer and stringbuilder?
What is a jagged array in java?
How does arraylist work in java?
Does java allow default arguments?
Which object oriented concept is achieved by using overloading and overriding?
How many types of exception can occur in a java program?
How you can force the garbage collection?