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


Please Help Members By Posting Answers For Below Questions

Differentiate between nested and inner class in java.

559


How will you initialize an Applet?

621


Does java allow overriding static methods ?

632


What is the main use of java?

573


Can variables be used in java without initialization?

552






Can a vector contain heterogenous objects?

601


What is a blocking method in Java?

606


What is difference between path and classpath in java?

487


What is byte code and why is it important to java’s use for internet programming?

594


What is the difference between the paint() and repaint() methods?

589


Is node a data type in java?

499


What is the effect of keeping a constructor private?

473


What is difference between null and void?

531


How infinite loop is declared?

537


What is a boolean used for?

590