2D Array & Inheritance Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something[2][1]?

2.3

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something.length?

3

Consider the following code segment: String[][] word = {{"DOE", "A","DEER"},{"A", "FEMALE", "DEER"}, {"RAY", "A", "DROP"},{"OF","GOLDEN","SUN"}}; int counter = 0; for(String[] row: word) { for(int j = 0; j< word[0].length; j++) { if(row[j].equals(word[j+1][j])) { counter++; } } } System.out.println(counter); What will the result of the print statement be when this code segment is executed?

4

Consider the following code segment: int[][] nums = new int[5][5]; for(int i = 0; i< nums.length; i++) { for(int j = 0; j< nums[0].length; j++) { nums[i][j] = i + j; } } How many instances of the number 5 will be stored in this 2D array?

4

Consider the following code segment: int[][] arr = {{10, 9, 8},{7, 6, 5}, {4, 3, 2}}; for(int row = 0; row < arr.length; row++) { for(int num: arr[row]) { System.out.println(arr[row][row] == num); } } How many times will the boolean expression printed from this code segment be true?

3

What goes in the missing code if the desired return is the following (as an example): This Tree is not an evergreen fruit tree

return super.toString() + " fruit tree";

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; How do you replace the value 13.21 with 8.8?

something[2][3] = 8.8;

Which of the following will print City Schools? I. Student jackson = new Student(); jackson.printSchool(); II. HSStudent jackson = new HSStudent(); jackson.printSchool(); III. MSStudent jackson = new MSStudent(); jackson.printSchool();

I, II only

Consider the following class declarations public class Car { /* Implementation Not Shown */ } public class ElectricCar extends Car { /* Implementation Not Shown */ } The following line of code appears in a test class: ArrayList<Car> cars = new ArrayList<Car>(); Which of the following objects can be added to the ArrayList? I. Car leaf = new ElectricCar(); II. Car mustang = new Car(); III. ElectricCar model3 = new ElectricCar();

I, II, III

If 4 BaseballTeam objects are created as such: BaseballTeam one = new BaseballTeam("Athletics", "Oakland"); BaseballTeam two = new BaseballTeam("Athletics", "Kansas City"); BaseballTeam three = new BaseballTeam("Athletics", "Oakland"); BaseballTeam four = two; Which of the following will print true? I. System.out.println(one.equals(three)); II. System.out.println(two.equals(four)); III. System.out.println(one == three); IV. System.out.println(two == four);

I, II, and IV Only

A code segment located in a different class produced the following output: Centennial park with a soccer field Which of the following code segments will produce that output? I. Park cent = new Park("Centennial", "soccer"); System.out.println(cent); II. Park cent = new Field("Centennial", "soccer"); System.out.println(cent); III. Field cent = new Field("Centennial", "soccer"); System.out.println(cent);

II and III Only

Given the following code: public int addNumbers(int one, int two) Which method will correctly override this method when placed in a subclass? I. public int addNumbers(int one, int two, int three) II. public int addNumbers(int one, int two) III. public int addNumbers(int a, int b) IV. public int addNumbers()

II and III only

Which of the following will print Los Angeles Dodgers?

Team dodgers = new BaseballTeam("Dodgers", "Los Angeles"); System.out.println(dodgers);

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; We want to replace the row {6.1, 10.2, 1.3, -2.5, -9.9} with a complete new array that looks like {3.1, 4.1, 5.9, 2.6, 8.4}.

double[] temp = {3.1, 4.1, 5.9, 2.6, 8.4}; something[1] = temp;

We want to create a 2D double array with 6 rows and 7 columns and assign it to connectFour. Which of these is correct?

double[][] connectFour = new double[6][7];

Given the following: String[][] poem = { {"I", "am", "the", "cookie", "monster."}, {"Would", "you", "like", "a", "cookie?"}, {"COOOOKIE", "OM", "NOM", "NOM", "NOM"} }; Which of the following code fragments would produce the following output? I am the cookie monster. Would you like a cookie? COOOOKIE OM NOM NOM NOM.

for (int line = 0; line < poem.length; line++) { for (int word = 0; word < poem[line].length; word++) { System.out.print(poem[line][word] + " "); } System.out.println(); }

Consider the following code segment, which is intended to create and initialize the 2D array words where the length of each word corresponds to the product of the indices of the row and the column it resides in. String[][] words = /*missing code */; Which of the following initializer lists could replace /*missing code*/ so that the code segment works as intended?

{{"", "", ""}, {"", "b", "be"}, {"", "do", "dont"}}

Given the definitions of class A and class B class A { public int i; public int j; public A() { i = 1; j = 2; } } class B extends A { int a; public B() { super(); } } what is the output of this code B obj = new B(); System.out.println(obj.i + " " + obj.j);

1 2

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something[1][2]?

1.3

Consider the following code segment: int[][]nums = {{1, 2, 3}, {100,200,300}, {4, 6, 5}, {7,8,6}}; int sum = 0; for(int row = 0; row < nums.length/2; row++) { for(int col = 0; col < nums[row].length/2; col++) { sum += nums[row][col]; } } System.out.println(sum); What will be displayed as a result of executing this code segment?

101

Which of the following statements will cause a compile-time error?

Parent person = new Child(); person.grade();

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something[2].length?

5

what does this program output? Shape shape1 = new Shape(); Shape shape2 = new Rectangle(); Shape shape3 = new Square(); Shape shape4 = new Circle(); System.out.println(shape1.getShapeName()); System.out.println(shape2.getShapeName()); System.out.println(shape3.getShapeName()); System.out.println(shape4.getShapeName());

Shape Rectangle Rectangle Circle

Which of the following is the best example of a Superclass / Subclass relationship?

Fruit / Banana

Which of the constructors that follow would be valid to put in the Vector3D class? Possible constructors for Vector3D: I. public Vector3D() {} II. public Vector3D(int x, int y, int z) { super(x,y); this.z = z; } III. public Vector3D(int x, int y) { super.x = x; super.y = y; this.z = 0; }

I and II

Which of the following objects can be passed as a parameter so that the code compiles and runs? I. OnlineCompany abc = new StartUp(); II. StartUp abc = new StartUp(); III. Company abc = new OnlineCompany();

I and II only

Which of the following could be the constructor for the Dog class? I. public Dog(String color) { super.type = "Dog"; this.color = color; } II. public Dog(String color) { super("Dog"); this.color = color; } III. public Dog(String type, String color) { super(type); this.color = color; }

II and III only

Given the following class structure, which class is on the top of the hierarchy? public class Grandparent { /* Implementation not shown */ } public class Parent extends Grandparent { /* Implementation not shown */ } public class Child extends Parent { /* Implementation not shown */ } public class GrandChild extends Child { /* Implementation not shown */ }

Object

The Java Classes Skeleton, Spider, and Zombie all extend the Java Class Monster. The Monster Class is defined below. public class Monster { private String name; private String type; private int x; private int y; public Monster(String name, String type) { this.name = name; this.type = type; this.x = 0; this.y = 0; } public void move(x, y) { this.x = x; this.y = y; } } What variables and methods do the Skeleton, Spider, and Zombie Classes inherit?

Only the method move

Which of the following best describes what will happen when the code is executed?

This code will create a superclass object by calling the no-argument Car constructor.

Does the Child printName method successfully override the Parent method?

Yes, the method is overridden correctly.

Which of the following traversals would print all of the elements in the 2D array of integers nums in row-major order?

for(int col = 0; col < nums.length; col++) { for(int row = 0; row < nums[col].length; row++) { System.out.println(nums[col][row]); } }

Which of the following traversals would print all of the elements in the 2D array of integers nums in column-major order?

for(int row = 0; row < nums[0].length; row++) { for(int col = 0; col < nums.length; col++) { System.out.println(nums[col][row]); } }

Which is the correct way to construct and assign a 2D array, with 8 rows and 10 columns, to the variable popcorn?

int[][] popcorn = new int[8][10];

What would be a correct way to instantiate this 2D array?

int[][] table = { {1, 0, 10, 0}, {3, 8, 38, 0} };

What goes in the missing code if the desired return is a square of the number?

return super.multiply(number, number);

What is the correct implementation for the subclass constructor?

super(evergreen); this.fruit = fruit;

Consider the following code segment, which is intended to display the word boards. String[][] twoLetters = {{"ab", "ac", "ad","ar","af"}, {"bo", "be", "bi", "ba", "bu"}, {"ca", "ce", "ck", "co", "cs"}, {"da", "ds", "do", "de", "di"}}; System.out.println(/*Missing Code*/); Which of the following can replace /*Missing Code*/ so the code segment works as intended?

twoLetters[1][0] + twoLetters[0][3]+ twoLetters[3][1]

Consider the following code segment: int[][] mystery = new int[3][3]; int counter = 0; while(counter < mystery.length) { for(int col = 0; col < mystery[counter].length; col++) { if(counter == 0) { mystery[col][counter] = 1; } else if(counter == 1) { mystery[counter][col] = 2; } else { mystery[counter][counter] = 3; } } counter++; } What will the value of each element in mystery be after the execution of the code segment?

{{1, 0, 0} {2, 2, 2} {1, 0, 3}}

Consider the following method, sumTo10, that traverses a 2D array checking to see if the sum of all integers in each array are equal to 10. The method will return true if all arrays within the 2D array sum to 10, and false otherwise. public static boolean sumTo10(int[][] nums) { for(int[] row: nums) { int sum = 0; int counter = 0; while(counter < nums.length) { sum+=row[counter]; counter++; } if(sum != 10) { return false; } } return true; } For example, the 2D array {{2,8}, {4, 6}} would return true because the content of each array sums to 10. The method, however, doesn't always work as intended. Which of the following 2D array input values does sumTo10 not work for?

{{9, 1, 0}, {4, 1, 5}}


संबंधित स्टडी सेट्स

5: Market Efficiency and Market Distortions: Practice Quiz

View Set

ATI PCCII Musculo Practice Questions

View Set

NU372 Week 1 EAQ Evolve Elsevier: Infection (Custom Quiz)

View Set