Menu
Question Index
...

What will be the output of the following program?

class CarTester
{
    public static void main(String s[])
    {
        Car car = new Car("Maruti", "Wagon R", 1000, 12.4);

        System.out.println(car.company + "'s " + car.model + " has engine power of " + car.cc + "cc.");
    }
}

class Car
{
    Car(String company, String model, int cc, double mileage)
    {
        company = company;
        model = model;
        cc = cc;
        mileage = mileage;
    }

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


Maruti's Wagon R has engine power of 1000cc.
null's null has engine power of 0cc.
Compilation Error - since the parameter name passed
to the constructor can not be the same as member variable.
Compilation Error - since there is no default constructor.

Doubts

Problems

Topic: this Keyword 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