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 + " has " + bike.cc + "cc power.");
    }
}

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

    Bike()
    {
    }

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


Compilation Error - since we can not have multiple constructors in a class.
Compilation Error - since we can not define a constructor with no parameters.
Every constructor should have at least one parameter.
Hero Honda's Shine has 125cc power.
Compilation Error - since the default constructor has to be
defined above the other constructors.

Doubts

Problems

Topic: Class With Multiple 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