Menu
Question Index
...

What will be the output of the following program?

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

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

class PrintA
{
    int printA = 5;
}

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


printA = 5
printB = 5
Multiply = 25
printA = 10
printB = 5
Multiply = 50
printA = 5
printB = 5
Multiply = 50
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