Question
The output of the method will be 1 1 3 3 or 1 1 3 3? Brackets or no brackets? public class Room { int
public class Room {
int width;
int length;
public Room(int w, int l) {
this.width = w;
this.length = l;
}
public String toString() {
return width + " " + length;
}
}
public class House {
int nFloors;
int nRooms;
static int numHouses = 0;
Room[] allRooms;
public House(int n1, int n2) {
nFloors = n1;
nRooms = n2;
allRooms = new Room[nRooms];
numHouses++;
}
public void printRooms() {
for (int i = 0; i < this.nRooms; i++) {
System.out.print(this.allRooms[i] + " ");
}
}
public static House renovation(House h) {
return new House(1, 2);
}
}
Suppose we have the following method in House class. What prints when the method is executed? public static void methodFour() { House h1 = new House (1, 2); House h2 = new House (2, 2); Room[] allRooms = new Room [2]; allRooms [0] = new Room (1, 1); allRooms [1] = = new Room (2, 2); hl.allRooms = allRooms; h2.allRooms [0] = allRooms [0]; h2.allRooms [1] = new Room (3, 3); allRooms [0] = new Room (5, 5); hl.allRooms [1] = new Room (4, 4); h2.printRooms(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started