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 = "Kirslokar";
        m.price = 15_234_0;
        w.manufacturer = "Godavari";
        w.price = 1_52_340;
        p(m.manufacturer, m.price);
        p(w.manufacturer, w.price);
        m = w;
        p(m.manufacturer, m.price);
        m.manufacturer = "General Motors";
        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 {}


Kirslokar#152340.0#Godavari#152340.0#Godavari#152340.0#General Motors#152340.0#
Kirslokar#152340.0#Godavari#152340.0#null#0.0#Godavari#152340.0#
Kirslokar#1523.4#Godavari#1523.4#null#0.0#Godavari#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