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 a boolean 1 bit?
Why java applets are more useful for intranets as compared to internet?
What are the approaches that you will follow for making a program very efficient?
what is optional in java 8?
How to instantiate member inner class?
What is number data type?
What is visibility mode?
What is final class?
What is void keyword?
What are the advantages of passing this into a method instead of the current class object itself?
What is a bubble sort in java?
What are recursive functions?
How will you add panel to a frame?
What is an abstract class and what is it’s purpose?
What is assembly language?