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 r * in math?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread
Can a static method be overridden in java?
What is dynamic array in java?
what is the difference between the methods sleep() and wait()? : Java thread
What are structs in java?
What is a newline character in java?
How do you sort data in java?
Is it possible to use string in the switch case?
Where is the find and replace?
These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }
Does treeset use compareto?
Explain working of call by reference function invoking.
what are the states associated in the thread? : Java thread
What are design patterns and please explain?