Menu
Question Index
...

What will be the output of the following program?

class Tricky {
    int num;
    Tricky(int n) {
        num = n;
    }
    Tricky inc() {
        Tricky temp = new Tricky(num + 10);
        return temp;
    }
}

public class TrickyQuestion {
    public static void main(String s[]) {
        Tricky num1 = new Tricky(10);
        Tricky num2;
        num2 = num1.inc();
        System.out.print("The program will display the output as: ");
        System.out.print(num1.num + ",");
        System.out.print(num2.num + ",");
        num2 = num1.inc();
        System.out.print(num2.num);
    }
}


The program will display the output as:
The program will display the output as: 10,10,10
The program will display the output as: 10,20,30
The program will display the output as: 10,20,20
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