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
What is string intern in java?
What is null statement?
What is skeleton and stub? What is the purpose of those?
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
Is java se open source?
Explain the hierarchy of java exception classes?
What will be the output of round(3.7) and ceil(3.7)?
Which class represents the socket that both the client and server use to communicate with each other?
Can we override private methods?
What happens to the Exception object after handling an exception?
What is difference between string and new string?
Is array synchronized in java?
What do you mean by aggregation?
What does super keyword do?
What isan abstract class and when do you use it?