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

Explain jvm, jre, and jdk?

678


What does .equals do in java?

603


What do you mean by garbage collection used in java?

663


What invokes a thread's run() method in java programming?

670


What are exception handling keywords in java?

703






Write an algorithm for quick sort?

691


What is the purpose of using the java bean?

681


How many return statement are allowed in a function?

550


What is string in java? String is a data type?

651


What are the advantages of java over cpp?

674


What is default exception handling in java?

645


Explain OOPs concept.

733


What is local declaration?

585


How do you convert boolean to boolean?

626


What is fail fast in java?

676