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


Please Help Members By Posting Answers For Below Questions

Is vector thread safe in java?

554


Can we have 2 main methods in java class?

537


What is the range of a character variable?

541


What is member in java?

490


What is an exception? difference between Checked and Unchecked exception in Java

552






Why are global variables used?

499


what is an objects lock and which objects have locks? : Java thread

532


What access modifiers can be used for variables?

579


Explain about assignment statement?

594


Why does it take so much time to access an applet having swing components the first time?

1392


What will happen when using pass by reference in java?

520


Why do we need hashset in java?

495


Objects or references which of them gets garbage collected?

530


What does function identity () do?

515


What is immutable in java?

538