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
Which number is denoted by leading 0x or 0x in java?
What is multi level inheritance in java?
What is the difference between static class and normal class?
Is node a data type in java?
Why is a singleton bad?
How to implement an arraylist in java?
How do you sort arrays in java?
Does java linked list allow duplicates?
What is the purpose of format function?
What happens when I use / and % with a negative numerator?
What does n mean?
What is a package in java? List down various advantages of packages.
What do you mean by checked exceptions?
What is the preferred size of a component in java programming?
How does indexof work?