Menu
Question Index
...

What will be the output of the following program?

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

        Bike bike2 = new Bike();
        bike2.company = "Yamaha";
        bike2.model = "RX100";
        bike2.mileage = 65.0;

        bike2 = bike1;
        bike1 = bike2;

        System.out.println(bike1.company + "'s " + bike1.model + " gives a mileage of " + bike1.mileage + "kmpl.");
        System.out.println(bike2.company + "'s " + bike2.model + " gives a mileage of " + bike2.mileage + "kmpl.");
    }
}

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


Hero Honda's Splendor gives a mileage of 54.8kmpl.
Yamaha's RX100 gives a mileage of 65.0kmpl.
Hero Honda's Splendor gives a mileage of 54.8kmpl.
Hero Honda's Splendor gives a mileage of 54.8kmpl.
Yamaha's RX100 gives a mileage of 65.0kmpl.
Yamaha's RX100 gives a mileage of 65.0kmpl.
Compilation Error - since the value of reference can not be changed
after it is initialized.

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