Menu
Topics Index
...
`

Room And Fan Output2506


If you need explanation Read this topic

If you need Answer Take test on this topic

Room And Fan Output2506
What will be the output of the following program?
public class RoomAndFan {
    public static void main(String[] args) {
        Room r = new Room();
        r.name = "Hall";
        r.flooring = "Marble";
        r.width = r.height = 12;
        r.fan.speed = 1500;
        r.fan.color = "Brown";
        r.fan.numberOfWings = 3;
        System.out.print(r.name + r.flooring + r.width + r.height);
        System.out.print(r.fan.speed + r.fan.color + r.fan.numberOfWings);
    }
}
class Room extends Fan {
    String name;
    String flooring;
    int width, height;
    Fan fan = new Fan();
}
class Fan {
    double speed;
    String color;
    int numberOfWings;
}

A. HallMarble12120.0Brown3
B. HallMarble241500.0Brown3
C. HallMarble12121500.0Brown3
D. Compilation Error or Runtime Error
Topic: Is-A Relationship In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B  in roomandfan class it prints and room class extends fan and all fan quality varibles intialised and used in

Posted by Bharath Yelchuri    2014-03-27 09:57:23


Ans is c we made a object r of room class in roomandfan class and is printed by print statement and room class extends fan class so all the variables can be used

Posted by Naga Sinst    2014-03-27 10:16:40


ans is c here we used inheritance so room class gets the variables of fan and he created the object and used it

Posted by Chintu Raparthi    2014-03-27 11:55:49


Congratulations Naga Sinst. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-28 04:29:45


doesn't it add r.width and r.height and print 24 ? :-)

Posted by Satish Kilaru    2014-03-28 04:48:14


Yes, if we use (r.name+r.flooring+(r.width+r.height)) :-). Since we are concatenating integer to string, it will just get added as a string instead of int.

Posted by Merit Campus    2014-03-28 08:47:40


In what order aw the arga processed?

Posted by Satish Kilaru    2014-03-28 21:59:55


Arguments are processed from left to right.

Posted by Merit Campus    2014-03-29 04:33:28


© meritcampus 2019

All Rights Reserved.

Open In App