Menu
Topics Index
...
`

Room And Fan Output2444


If you need explanation Read this topic

If you need Answer Take test on this topic

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

class Fan extends Room {    double speed;    String color;    int numberOfWings;    }

A. 1500.0Brown3
HallMarble24
B. 1500.0Brown4
HallItalianMarble37
C. 1500.0Brown3
HallMarble1212
D. Some other output
E. 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 E..run time error bcz fan in room is not define n we are accsing it..so it wl give run time error..nul pointer exception

Posted by Uday Kumar    2014-06-11 12:56:09


Ans is c....object r accesses all variables in room and r.fan will be used to access the variables in class fan...So,the answer is 1500.0Brown3\nHallMarble1212

Posted by Badam Swathi    2014-06-11 14:41:56


ans e ....accesing fan class using variable of room causes a compilation error.

Posted by Manasa Jyothi Sree    2014-06-11 14:44:14


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

Posted by Merit Campus    2014-06-12 03:57:21


© meritcampus 2019

All Rights Reserved.

Open In App