For unlimited access to Study Guides, a Grade+ subscription is required.
(b) Consider the following classes: public class House - ي شما هر چند = = private String rooms; public House() String rooms - new String [31; rooms (0) - "living room"; rooms [1] - "kitchen"; rooms (2) - "bedroom"; = public void print RoomList () for (int i-0; i < rooms.length; i++) { System.out.println (rooms[1]); = ہم نوا شهيد - public class Block يا نو public static void main(String[args) له House myblouse - new House(); myHouse.print RoomList(); د ه د The program compiles, but when you run the program, you get the following exception: Exception in thread "main" java.lang.NullPointerException at House.print RoomList (House.java:12) at Block.main (Block.java:6) The point of the method printRoomList is to print all the Strings in the house to the screen. Why does it give the error and write the code to fix the error while successfully printing all the rooms to the screen?
(c) Consider the following class: public class Student Grades private int ( grades; 1/loads values into grades from a file public void initializeFromFile(String filename) ....! //gets the total number of grades entered public int get NumRecords () (....) public class WebCT 1 public static void main(String[] args) Student Grades grades = new Student Grades(); grades.initializeFromFile("records. L.sv"); System.out.println("There are " + grades.length file.") " grades in that The goal of the program is to load the files and then print the total number of grades in the file. However, when you try to compile the above classes, you get the following error: WebCT.java:5: cannot find symbol symbol : variable length location: class Student Grades System.out.println("There are " + grades.length + " grades in that file." Explain why the crror occurs and write the code to fix it (while maintaining the intended functionality).
17. What does the following piece of code print? public class Test public static void main(String[] args) int[] a = {2,4,6,8); for(int i = 0; i < a.length; i++) int() b = foo (a); System.out.print( b[i] + " "); public static int[] foo (int[] array) for (int i = 0; i < array.length; i++) array[i]++; return array; (A) 3 579 (B) It would give compile-time error. (C) 3 6 9 12 (D) It would give run-time error. (E) 2468