Menu
Question Index
...

What will be the output of the following program?

class OutPut
{
    int c;

    public static void main(String[] args)
    {
        PrintA a = new PrintA();
        PrintB c = new PrintB();

        System.out.println("printA = " + a.printA);
        System.out.println("printB = " + c.printB);

        System.out.println("c = " + new OutPut().c);
    }
}

class PrintA
{
    int printA;
}

class PrintB
{
    int printB = 5;
}


printA = 0
printB = 5
c =
(some object reference value)
printA = 0
printB = 5
c = 0
Compilation Error
Runtime Error

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App