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 immutable in java?

786


What is a functional interface?

768


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

880


Does java runtime require a license?

786


What is string :: npos?

792


Why Set interface contains unique elements, what internally implemented for this so that it contains unique elements?

7745


What is stringwriter?

741


Can there be an abstract method without an abstract class?

734


What are the different tags provided in jstl?

769


What is equlas() and hashcode() contract in java? Where does it used?

829


How do you empty a list in java?

767


What are the three types of design patterns?

743


What is an infinite loop in java? Explain with an example.

802


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

773


Can you write a java class that could be used both as an applet as well as an application?

721