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

What is a Presistent Object?

649


Describe what a thread-local variable is in java?

577


Explain wait() method of object class ?

640


How will you reverse a link list without using recursion?

603


What is argument in java?

547






What is hashset in java?

541


When super keyword is used?

600


What does ide stand for?

529


What is continuity of a function?

528


How to change the priority of thread or how to set priority of thread?

568


What is difference between iterator and enumeration in java?

527


What is difference between synchronize and concurrent collection in java?

526


What is meant by call by reference?

519


What is anti pattern in java?

520


How does hashset works in java?

545