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
Say any two properties in beans?
Which is bigger float or double?
Is set ordered?
What is the difference between stringbuffer and stringbuilder class?
What is rule of accessibility in java?
What is array list in java?
Can a abstract class be defined without any abstract methods?
How do you find the absolute value?
How to access arraylist elements in java?
How to create packages in java?
What are methods in java?
What is the difference in between cpp and java? Can u explain in detail?
Can you run java program without main method?
What is difference between path and classpath in java?
What is the use of parse function in java?