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?

Answers were Sorted based on User's Feedback



Does a class inherit the constructor of its super class?if it does, how can you hide that construc..

Answer / pandu

Hi ,
constructor is never been inherited from superclass to
subclass.
we can call the Super class constructor in Sub class
by using
Super();
that too this stement should be first line in method.

Best Regards.

Is This Answer Correct ?    10 Yes 1 No

Does a class inherit the constructor of its super class?if it does, how can you hide that construc..

Answer / 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

More Core Java Interview Questions

What is local class in java?

0 Answers  


Why is an interface be able to extend more than one interface but a class can’t extend more than one class?

0 Answers  


How the elements are organized in CardLayout?

5 Answers  


What differences exist between iterator and listiterator?

0 Answers  


Is 0 an irrational number?

0 Answers  






Java does not support multiple inheritance. how interface helps in the same?

5 Answers   TCS,


While opening the file, what type of exceptions can be caught?

3 Answers  


What is the difference between a local variable and an instance variable?

0 Answers  


What is the use of object and class classes?

0 Answers  


what is the use of custom tags? with example?

1 Answers   Photon,


What is the synchronized method modifier?

0 Answers  


How does linkedlist work in java?

0 Answers  


Categories