Menu
Question Index
...

What will be the output of the following program.

class BikeTester
{
    public static void main(String s[])
    {
        Bike bike = new Bike("Hero Honda", "Shine", 125);
        bike.mileage = 72.5;
        bike.diskBrakes = false;

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

class Bike
{
    Bike(String companyParam, String modelParam, int ccParam)
    {
        company = companyParam;
        model = modelParam;
        cc = ccParam;
    }

    String company;
    String model;
    int cc;
    double mileage;
    boolean diskBrakes;
}


Compilation error - since in the Bike class constructor - mileage and diskBrakes are not initialized.
Compilation error - since data is assigned to member variables - mileage and diskBrakes - after the object is created.
Compilation error - since in the Bike class constructor, the parameter names companyParam, modelParam and ccParam are different from member variables company, model and cc.
Hero Honda's Shine gives a mileage of 72.5kmpl.

Doubts

Problems

Topic: Create Objects Using Constructors 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