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 an object's lock and which object's have locks in java programming?
Define a java class.
What is the purpose of the finally clause of a try-catch-finally statement in java programming?
Explain about sets?
What is double data type?
When is an object subject to garbage collection?
Can you call a method on a null object?
What is meant by class?
What are static blocks in java ?
What is the importance of finally block in exception handling?
Why are arrays useful in java?
Write a factorial program using recursion in java?
What is private public protected in java?
What are the different collection views provided by maps?
Is array primitive data type in java?