Menu
Question Index
...

What will be the output of the following program?

class OutPut
{
    public static void main(String[] args)
    {
        PrintA a = new PrintA();     // LINE 1
        PrintB c = new PrintB();     // LINE 2
        
        int multiply = a.printA * c.printB;

        System.out.println("printA = " + c.printA);
        System.out.println("printB = " + c.printB);
        System.out.println("Multiply = " + multiply);
    }
}

class PrintA
{
    int printA = 5;
}

class PrintB extends PrintA
{
    int printA = 10;
    int printB = 5;
}


printA = 10
printB = 5
Multiply = 50
printA = 10
printB = 5
Multiply = 25
printA = 5
printB = 5
Multiply = 25
Compilation Error
Runtime Error

Doubts

Problems

Topic: Assigning Sub Class Object To Super Class Reference In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App