Menu
Topics Index
...
`

Class Inheritance Program Output


If you need explanation Read this topic

If you need Answer Take test on this topic

Class Inheritance Program Output
What will be the output of the following program?
class ClassInheritance
{
    public static void main(String s[])
    {
        A a = new A();
        a.i = 4;
        B b = new B();
        b.i = 10; // LINE X
        b.j = 20;

        System.out.println("i = " + a.i);
    }
}

class A
{
    int i;
}

class B // LINE Y
{
    int j;
}

A. Compilation Error at LINE Y - since class B is not extending class A
B. i = 4
C. i = 10
D. Compilation Error at LINE X - since the member variable i is not accessible in b's object
Topic: Java Class Inheritance

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.

d compilation error since i is not a variable of class B

Posted by Ramesh Velpukonda    2014-09-03 03:49:25


d.since i is a membr of clas a..n cannot be accesed in b's objct

Posted by Asma Mujtaba Khan    2014-09-03 03:50:23


D

Posted by Akshay Bansod    2014-09-03 05:08:16


D

Posted by Raju VarshnEy    2014-09-03 07:26:20


D

Posted by Zeg Abder    2014-09-03 08:38:01


Congratulations Ramesh Velpukonda. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-04 04:17:12


© meritcampus 2019

All Rights Reserved.

Open In App