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
Why does java not support operator overloading?
How would overload a function based on return type?
Why pointers are not used in java?
how to deploy tomcatserver to weblogic server? write d following steps?
What is the difference between final, finally and finalize()?
What is the difference between overriding and overloading in OOPS.
What is null data type?
What is meant by overloading?
Is oracle charging for java?
What are the states of thread in java?
What is preparedstatement in java?
What is sizeof in java?
Can variables be used in java without initialization?
What is palindrome in java?
How do you sort arrays in java?