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

An inner class can actually be a subclass of the outer class? a. true b. false

2 Answers  


What is difference between fail-fast and fail-safe?

0 Answers  


Describe string intern() methodology

0 Answers  


who can we create the object of a class? in how many ways we can create it (max 5)

2 Answers  


when asub class inherits a super class and overrides a public method of super class in sub class(public method in super class). why these methods needs to be public in sub class. (otherwise compile time error).

3 Answers  


What is meant by flickering?

0 Answers  


Explain the difference between a Thread and a Process.

0 Answers   Ciena,


how to connect one jsp page to another jsp page????

6 Answers   IIT, Symphony,


What is variable declaration and definition?

0 Answers  


Difference between canvas class & graphics class?

1 Answers  


What are access specifiers available in java?

0 Answers  


We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.

2 Answers  


Categories