Menu
Question Index
...

What will be the output of the following program?

public class OverloadingDemo
{
    short variable = (1);
    OverloadingDemo()
    {
        ++variable;
        ++variable;
    }
    OverloadingDemo(OverloadingDemo oD)
    {
        ++oD.variable;
        ++variable;
    }
    public static void main(String[] args)
    {
        OverloadingDemo demo1 = new OverloadingDemo();
        OverloadingDemo demo2 = new OverloadingDemo(demo1);
        System.out.print(demo2.variable - demo1.variable);
    }
}


-2
2
6
8
Compilation Error or Runtime Error

Doubts

Problems

Topic: Class With Multiple Constructors In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App