Answer Posted / qim2010
this() is used to invoke a constructor of the same class
super() is used to invoke a super class constructor and
Example of using this():
public Pet(int id) {
this.id = id; // “this” means this object
}
public Pet (int id, String type) {
this(id); // calls constructor public Pet(int id)
this.type = type; // ”this” means this object
}
Example of using super():
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 | 0 No |
Post New Answer View All Answers
What modifiers may be used with a top-level class?
Why super is first line in java?
How to optimize the javac output?
What are the access modifiers available in java?
What is class??
Where is const variable stored?
How do you use parseint in java?
Is java good for beginners?
What is the use of callablestatement?
What are heap memory and stack memory and what are memory tables.
What is the collections api in java programming?
Is void a wrapper class?
What is the difference between delete and delete[]
What are facelets templates?
What is jee6?