in a constructor what happen if u call super and this in
the same class? i know that it is not possible to call
both in the same one? if we call what will happen?
Answer Posted / jyotshna pardhia
In a constructor if we call super and this in
the same class than we will get compile time error saying
that call to this() must be the first statement of the
construtor OR call to super() must be the first statement
of the constructor.So it is not possible to call
both in the same one.
Ex:-1
class Test
{
Test()
{
super();
this();
systm.out.println("hello Jyotshna");
}
}
error:- call to this() must be the first statement of
constructor.
Ex:-2
class Test
{
Test()
{
this();
super();
systm.out.println("hello Jyotshna");
}
}
error:- call to super() must be the first statement of
constructor.
Thanks & Regards
jyotshna
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is <> used for in java?
what is aggregation in java?
If I only change the return type, does the method become overloaded?
Is integer immutable in java?
What is hasnext in java?
What are the differences between graph and tree?
What is autoboxing and unboxing?
Write a program to solve producer consumer problem in java?
Can you sort a string in java?
Can we print null in java?
What are anonymous inner classes?
Why do we need variables?
What is a class reference?
Explain the difference between serializable and externalizable in java?
what is ststic with example