Menu
Question Index
...

What will be the output of the following program?

class GoodBoy {
    int a;
    private final int b;
    static int c = 7;
    GoodBoy() {
        a = 77;
        b = 55;
        c = 33;
    }
    public void getBoy() {
        System.out.print("-GoodBoy-");
    }
}
class GoodGirl extends GoodBoy {
    int a;
    private final int b;
    static int c = 40;
    GoodGirl() {
        a = 33;
        b = 22;
        c = 11;
    }
    public void getBoy() {
        System.out.print("-GoodGirl-");
    }
}
public class SolveIt {
    public static void main(String arg[]) {
        GoodBoy a = new GoodBoy();
        GoodBoy b = new GoodGirl();
        a.getBoy();
        b.getBoy();
        System.out.print("-" + GoodBoy.c + "-");
        System.out.print("-" + GoodBoy.c + "-");
    }
}


-GoodBoy--GoodGirl--7--7-
-GoodBoy--GoodGirl--33--11-
-GoodBoy--GoodGirl--33--33-
-GoodBoy--GoodGirl--40--40-
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static Keyword 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