Menu
Question Index
...

What will be the output of the following program?

class BikeTester
{
    public static void main(String s[])
    {
        Bike shine = new Bike();
        shine.company = "Hero Honda";
        shine.model = "Shine";
        shine.mileage = 72.5;

        Bike pulsar = shine;
        pulsar.company = "Bajaj";
        pulsar.model = "Pulsar";
        pulsar.mileage = 55.2;
        pulsar.diskBrakes = true;
        
        System.out.println(shine.company + "'s " + shine.model + " gives a mileage of " + shine.mileage + "kmpl.");
        System.out.println(pulsar.company + "'s " + pulsar.model + " gives a mileage of " + pulsar.mileage + "kmpl.");
    }
}

class Bike
{
    String company;
    String model;
    int cc;
    double mileage;
    boolean diskBrakes;
}


Compilation Error - since shine bike object can not be assigned to pulsar.
Hero Honda's Shine gives a mileage of 72.5kmpl.
Bajaj's Pulsar gives a mileage of 55.2kmpl.
Compilation Error - since diskBrakes is not initialized for shine bike object.
Bajaj's Pulsar gives a mileage of 55.2kmpl.
Bajaj's Pulsar gives a mileage of 55.2kmpl.

Doubts

Problems

Topic: Class References And Objects 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