0

i want to call there A's class constructor using "super" keyword how it is possible
help me plz.....

class A
{}

class B extends A
{}
class C extends B
{
i want to call here A's class constructor using "super" keyword how it is possible 
help me plz.....
}
class D
{
 A a=new A();
}
4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by stultuske
0

All constructors automatically call the immediate superclass's no-args constructor super() as the first line, unless you code an explicit call to a constructor of the immediate superclass yourself as the first line of your constructor.
If no constructor is defined for a class, the compiler creates an empty no-args constructor, which, as described above, automatically calls super().
This guarantees that, no matter what you do, when you call a new C(); a constructor for class A will be executed first, followed by a constructor for class B followed by a constructor for class C.

Short answer: No matter what you do or don't code, A's constructor will always be called. You can't prevent it.

0

unless you decide to add a constructor to A, which does take parameters, then you'll need to add the call to super in the constructor of B, with a parameter.

if you don't, the (automatically) ran super(); will try to find the public A(), won't find it, and bleep ... your code won't compile, since you're trying to access a non-existing constructor.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.