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 is primitive array?
Does apple use java?
Are primitives objects?
If I only change the return type, does the method become overloaded?
What is Enum in Java?
What does += mean in java?
What are the ways in which a thread can enter the waiting state?
Is string is a keyword in java?
Define an applet in java?
What is the meaning of immutable regarding string?
worst case complexities of Quick sort and Merge sort.
Why is java logo a cup of coffee?
What is the difference between compile-time polymorphism and runtime polymorphism?
What is variable in java?
What’s the difference between the methods sleep() and wait()?