Menu
Topics Index
...
`

Print abcd values


If you need explanation Read this topic

If you need Answer Take test on this topic

Print abcd values
What will be the output of the following program?
public class Family {
    public static void main(String[] args) {
        GS gs = new GS();
        gs.a = 10;
        gs.b = 20;
        gs.c = 30;
        System.out.println(gs.a + ", " + gs.b + ", " + gs.c + ", " + gs.d);
    }
}
class F {
    int a;
}
class M extends F {
    int b;
}
class S extends M {
    int c;
}
class GS extends S {
    int d = 40;
}

A. 10, 20, 30, 0
B. 10, 20, 30, 40
C. Compilation Error
D. Runtime Error
Topic: Multilevel Inheritance In Java With Example Program

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

answer is [B] as subclass object can access all its super class properties and methods

Posted by Ashok Kumar Paritala    2014-06-12 09:04:18


ans is b...al the variables are inhertd into the subclses

Posted by Vijay Kumar    2014-06-12 09:12:39


Congratulations Ashok Kumar Paritala. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-13 04:09:43


© meritcampus 2019

All Rights Reserved.

Open In App