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
Is vector thread safe in java?
Can we have 2 main methods in java class?
What is the range of a character variable?
What is member in java?
What is an exception? difference between Checked and Unchecked exception in Java
Why are global variables used?
what is an objects lock and which objects have locks? : Java thread
What access modifiers can be used for variables?
Explain about assignment statement?
Why does it take so much time to access an applet having swing components the first time?
What will happen when using pass by reference in java?
Why do we need hashset in java?
Objects or references which of them gets garbage collected?
What does function identity () do?
What is immutable in java?