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
Is set sorted in java?
How to compare two strings in java program?
What is treeset and treemap in java?
Difference between string, stringbuffer and stringbuilder?
What do you understand by classes in java?
What is the integer of 16?
What is the importance of static variable?
can any body body expalin best definitions & best real time exaples for opps concepts.
FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?
Explain the protected field modifier?
Which class cannot be a subclass in java?
Is java same as core java?
Does set allows null in java?
Which is illegal identifier in java?
What is difference between path and classpath variables?