Menu
Question Index
...

What will be the output of the following program?

class ComplexType
{
    int a;
    int b, total;
    int c;
    ComplexType(int a, int b, int c, int total) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.total = total;
    }
    ComplexType(int a, int b, int c) {
        this(a, b, c, a + c + 3);
    }
    
    public void print() {
        System.out.println("c = " + c + " total = " + total);
        c = total;
    }
    public static void main(String[] args) {
        ComplexType t1 = new ComplexType(4, 7, 2, 4 + 7 + 2);
        t1.print();
        ComplexType t2 = new ComplexType(t1.a, t1.c, t1.b);
        t2.print();
    }
}


c = 2 total = 13
c = 7 total = 14
c = 2 total = 13
c = 2 total = 14
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App