Menu
Topics Index
...
`

Class Definition Output


If you need explanation Read this topic

If you need Answer Take test on this topic

Class Definition Output
What will be the output of the following program?
class DefineClasses
{
    int c;

    public static void main(String[] args)
    {
        A a = new A();
        B b = new B();
        System.out.println("a = " + a.a);
        System.out.println("b = " + b.b);
        System.out.println("c = " + c);
    }
}

class A { int a; }

class B { int b = 5; }

A. a = 0
b = 5
c = 0
B. a = 0
b = 0
c = 0
C. Compilation Error
D. Runtime Exception
Topic: Static and Non Static Variables - Static and Non Static Methods

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.

Ans c..C is non static cant acces from static method

Posted by Vicky Maduri    2014-08-08 03:58:52


ans is c

Posted by Ramya Reddy Addulla    2014-08-09 14:47:31


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

Posted by Merit Campus    2014-08-11 04:25:09


© meritcampus 2019

All Rights Reserved.

Open In App