Menu
Question Index
...

What will be the output of the following program?

public class MotorsAndPrices {
    public static void main(String[] args) {
        Motor m = new Motor();
        WaterMotor w = new WaterMotor();
        m.manufacturer = "Suguna";
        m.price = 15_234_0;
        w.manufacturer = "VGuard ";
        w.price = 1_52_340;
        p(m.manufacturer, m.price);
        p(w.manufacturer, w.price);
        m = w;
        p(m.manufacturer, m.price);
        m.manufacturer = "Falcon";
        p(w.manufacturer, w.price);
    }
    private static void p(String manufacturer, double price) {
        System.out.print(manufacturer + "#" + price + "#");
    }
}
class Motor {
    String manufacturer;
    double price;
}
class WaterMotor extends Motor {
    String manufacturer;
    double price;
}


Suguna#152340.0#VGuard#152340.0#VGuard#152340.0#Falcon#152340.0#
Suguna#152340.0#VGuard #152340.0#null#0.0#VGuard #152340.0#
Suguna#1523.4#VGuard#1523.4#null#0.0#VGuard#1523.4#
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Class Inheritance

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App