Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The output of the method will be 1 1 3 3 or 1 1 3 3? Brackets or no brackets? public class Room { int

The output of the method will be "1 1 3 3" or 1 1 3 3? Brackets or no brackets?


 

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Prove that L(G) = {ww R } is not regular using the Pumping Lemma.

Answered: 1 week ago