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);

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

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

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


Compilation Error - since we can not have a method inside a class.
Maruti's Wagon R has engine power of 1000cc.
Compilation Error - since the variables company, model and cc are not accessible in
the method printCarSummary()
Compilation Error - since every method should have at least one parameter.



Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App