Java Constructor

class Nest
{

Nest()
{
System.out.print("Nest");
}

Nest (long l)
{
this();
System.out.print(l);
}

Nest(int i)
{
this(i);
System.out.print(i*2);
}

}


Public static void main(String[] args)
{
int i = 4;
new Nest(i);
}

What would be the output?

Options
- Nest48
- Nest84
- Nest44
- Compile Error


CORRECT ANSWER : Compile Error

Discussion Board
C

Very fine work

Lad Atul Vijay 03-10-2017 03:15 AM

cannot call constructor recursively

recursive call on Nest(int i) constructor will not compile "recursive constructor invocation"

G 12-1-2014 10:09 PM

Solu

calling this() calling own constructorconstructor now allowed in JAVA we can call using new Test()

Manish Malaviya 11-20-2014 06:34 AM

Write your comments

 
   
 
 

Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement