Menu
Question Index
...

What will be the output of the following program?

public class ConstructorsUsingThis {
    public static void main(String[] args) {
        new A().print();
        new A(15).print();
        new A('A').print();
        new A(15, 34.5).print();
        new A(16, 16.0, 16.0f).print();
    }
}
class A {
    int i = 20;
    double j = 35.6;
    float k = 121.3f;
    char c = 'C';
    A() {}
    A(int i) { this.i = i; }
    A(int i, double j) { this(i); this.j = j; }
    A(int i, double j, float k) { this((int) j, i); this.k = k; }
    A(char c) { this(c, c); k = c; this.c = c; }
    public void print() {
        System.out.print("[" + i + "," + j + "," + k + "," + c + "]");
    }
}


[20,35.6,121.3,C][15,35.6,121.3,C][65,65.0,65.0,A][15,34.5,121.3,C][16,16.0,16.0,C]
[20,35.6,121.3,C][15,35.6,121.3,C][20,35.6,121.3,A][15,34.5,121.3,C][16,16.0,16.0,C]
Some other output
Compilation Error

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App