Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How are this and super used?

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


Please Help Members By Posting Answers For Below Questions

What are methods and how are they defined?

1194


What is immutability in java?

1059


Are the imports checked for validity at compile time? Will the code containing an import such as java.lang.abcd compile?

1090


How to sort array of 0 and 1 in java?

931


What is a heavyweight component?

1011


Can we declare a constructor as final?

1287


Can we have two main methods in a java class?

1033


Which is better 64 bit or 32 bit?

927


Is array serializable java?

954


Where can I find jdk in my computer?

957


How do you declare an array in java?

1034


How do you check if a character in a string is a digit or letter?

1052


What is default size of arraylist in java?

1126


Is null in java?

984


How do you sort objects in java?

943