Menu
Question Index
...

What will be the output of the following program?

class MarkerInterfaces {

    public static void main(String[] args) {
        System.out.println("G = " + G.PI);
        System.out.println("H = " + H.PI);
        CG cg = new CG();
        System.out.println("cg = " + cg.PI);
        cg.PI *= 2;
        System.out.println("cg = " + cg.PI);
        System.out.println("G = " + G.PI);
    }
}

interface G {

    double PI = 3.14;
}

interface H extends G {

    double PI = 3.145;
}

class CG implements G {

    double PI = 3.1451;
}


G = 3.14
H = 3.14
cg = 3.14
cg = 3.14
G = 3.14
G = 3.14
H = 3.14
cg = 3.1451
cg = 6.2902
G = 3.14
G = 3.14
H = 3.145
cg = 3.1451
cg = 6.2902
G = 3.14
G = 3.14
H = 3.145
cg = 3.1451
cg = 6.2902
G = 6.2902
Compilation Error

Doubts

Problems

Topic: Creating Interface In Java With Example Program

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App