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

Does a class inherit the constructor of its super class?if
it does, how can you hide that constructor? if it doesnot
how can you call it from the sub class?

Answer Posted / hanu

there is an exceptional case for this.i.e when you call
derived class parameterised constructor and if you do not
call any of the super class constructor then bydefault the
superclass default constructor gets executed prior to the
derived argument constructor then the derived class
parameterised constructor gets executed.

example code:

class A
{
A()
{
System.out.println("in Class A");
}
A(int c)
{
System.out.println("in Class A"+c);
}
};
class B extends A
{
B()
{
System.out.println("in Class B");
}
B(int z)
{

System.out.println("in Class B"+z);
}
};


class Dead
{
public static void main(String[] args)
{
System.out.println("Hello World!");
//B b=new B();
B d=new B(20);


}
}

output:

---------- java ----------
Hello World!
in Class A
in Class B20

Output completed (0 sec consumed) - Normal Termination

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can constructor be inherited?

976


What is a finally block?

923


What is bom encoding?

945


What is sortedmap interface?

938


How do you achieve polymorphism in java?

928


What is the use of beaninfo?

979


What are classloaders?

961


What are singleton services?

837


Is double bigger than float?

911


What is the meaning of flag day?

959


What are advantages of using Java?s layout managers than windowing systems?

2314


Does java have a compiler?

976


How destructors are defined in java?

1118


Why we go for collections in java?

918


I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?

930