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...

in a constructor what happen if u call super and this in
the same class? i know that it is not possible to call
both in the same one? if we call what will happen?

Answer Posted / madhu

We can't give both super() and this()in a constructor,
because both of these statements must be the first
statements in constructor. if you give super() as the first
statement then compiler error will come with this() call.
and vice versa.
but you can call the members with both super and this in a
constructor. here is the code.
class Base
{
Base()
{
System.out.println("Base constructor");
}
void m1()
{
System.out.println("m1 of Base");
}
}
class Derived extends Base
{
Derived()
{
super();//it is ok.
this();//raises compiler error
//but we can call the members with super and this
super().m1();//make sure that super()in
line must be marked comment
this().m1();
System.out.println("Derived constructor");
}
void m1()
{
System.out.println("m1 of Derived");
}
public static void main(String[] args)
{
Derived d=new Derived();
}
}
it works out

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of web technologies?

1034


What is a super method?

967


Name some classes present in java.util.regex package.

1022


What are different types of states exist for a thread?

1000


Explain the difference between string, stringbuffer and stringbuilder in java?

989


How do you find the independent variable?

1038


When should a function throw an exception?

1024


Does string isempty check for null?

1003


Explain different ways of creating a thread?

1036


What is the difference between yield() and sleep()?

997


What is the public field modifier?

1009


What is a vector in java?

1014


What are the types of exceptions?

1036


How many arguments can be passed to main ()?

983


Is 0 an irrational number?

1052