How do we call the super class Constructor?
>> Sunday, May 29, 2011
If a class called “SpecialPet” extends your “Pet” class then you can
use the keyword “super” to invoke the superclass’s constructor.
To call a regular method in the super class use: “super.myMethod( );”. This can be called at any line. Some
frameworks based on JUnit add their own initialization code, and not only do they need to remember to invoke
use the keyword “super” to invoke the superclass’s constructor.
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. Some
frameworks based on JUnit add their own initialization code, and not only do they need to remember to invoke
0 comments:
Post a Comment