Java Exam 2 review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A ragged array is __________. a. a two-dimensional array where the rows have different numbers of columns b. a one-dimensional array for which the number of elements is unknown c. a two-dimensional array for which the number of rows is unknown d. a partially initialized two-dimensional array of ranged values

A

Every object in Java knows its own class and can access this information through method . a. getClass. b. getInformation. c. objectClass. d. objectInformation.

A

If the following is from the method section of a UML diagram, which of the statements below is true? + equals(object2:Stock) : Boolean a. This is a public method that accepts a Stock object as its argument and returns a boolean value. b. This is a public method that returns a reference to a String object. c. This is a private method that receives two objects from the Stock class and returns a boolean value. d. This is a private method that returns a boolean value.

A

In order to do a binary search on an array __________. a. the array must first be sorted b. you must first do a sequential search to be sure the element you are looking for is there c. the values of the array must be numeric d. no requirements are necessary

A

The __________ method removes an item from an ArrayList at a specific index. a. remove b. pop c. deleteAt d. clear

A

What type of relationship exists between two objects when one object is a specialized version of another object? a. "is a" c. "has a" b. "contains a" d. "consists of"

A

When a method is declared with the __________ modifier, it cannot be overridden in a subclass. a. final b. super c. void d. public

A

__________ is the term for the relationship created by object aggregation. a. "Has a" c. "Is a" b. Inner class d. One-to-many

A

When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable? a. A syntax error occurs. b. A compile-time error occurs. c. A run-time error occurs. d.The program compiles and runs because the instance variables are initialized to their default values.

D

All methods specified by an interface are __________. a. private b. public c. protected d. static

B

Assigning a subclass reference to a superclass variable is safe ________. a. because the subclass object has an object of its superclass. b. because the subclass object is an object of its superclass. c. only when the superclass is abstract. d. only when the superclass is concrete.

B

Every class in Java, except ________, extends an existing class. a. Integer. b. Object. c. String. d.Class.

B

Given the following code, which statement is true? public class ClassB implements ClassA{ } a. ClassA must override each method in ClassB. b. ClassB must override each method in ClassA. c. ClassB inherits from ClassA. d. ClassA inherits from ClassB.

B

Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the ordinal value of the MAPLE enum constant? a. 0 b. 1 c. 2 d. 3

B

If the superclass contains only abstract method declarations, the superclass is used for ________. a. implementation inheritance. b. interface inheritance. c. Both. d. Neither.

B

In __________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass. a. pseudocode c. c. CRC card b. a UML diagram d. a hierarchy chart

B

In an inheritance relationship __________. a. the subclass constructor always executes before the superclass constructor b. the superclass constructor always executes before the subclass constructor c. the constructor with the lowest overhead always executes first regardless of inheritance in subclasses d. the unified constructor always executes first regardless of inheritance

B

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC a. ClassA c. ClassC b. ClassB d. cannot tell

B

The ___________ method is used to insert an item into an ArrayList. a. insert b. add c. store d. putItem

B

Which of the following is a correct method header for receiving a two-dimensional array as an argument? a. public static void passMyArray(int[1, 2]) b. public static void passMyArray(int[][]) c. public static void passMyArray[1][2]) d. public static void passMyArray(int[],int[] myArray)

B

private fields of a superclass can be accessed in a subclass a. by calling private methods declared in the superclass. b. by calling public or protected methods declared in the superclass. c. directly. d.All of the above.

B

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9]; a. The numbers array has 54 rows. b. The numbers array has 15 rows. c. The numbers array has 6 rows and 9 columns. d.The numbers array has 6 columns and 9 rows

C

If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts? a. numAccounts = account20.numAccounts; b. numAccounts = numOfAccounts; c. numAccounts = SavingsAccount.numberOfAccounts; d. numAccounts = account20;

C

It is common practice to use a __________ variable as a size declarator. a. static b. reference c. final d. boolean

C

The __________ key word is used to call a superclass constructor explicitly. a. goto b. this c. super d. extends

C

What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>(); a. It specifies that String objects may not be stored in the ArrayList object. b. It specifies that everything stored in the ArrayList object will be converted to a String object. c. It specifies that only String objects may be stored in the ArrayList object. d. It specifies that the ArrayList will be converted to a String array.

C

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } } a. Nothing is wrong with this code. b. The method super is not defined. c. The call to the method super must be the first statement in the constructor. d. No values may be passed to super.

C

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; } a. 50 b. 55 c. 60 d. 65

C

The only limitation that static methods have is __________. a. they must be declared outside of the class b. they cannot refer to nonstatic members of the class c. they can only be called from static members of the class d. they can refer only to nonstatic members of the class

B

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; } a. 170 b. 180 c. 190 d. 200

B

When a reference variable is passed as an argument to a method __________. a. a copy of the variable's value is passed into the method's parameter b. the method has access to the object that the variable references c. the method becomes a static method d. the program terminates

B

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) { value += array1[a]; } a. value contains the highest value in array1. b. value contains the lowest value in array1. c. value contains the sum of all the values in array1. d. This code would cause the program to crash.

C

When you make a copy of the aggregate object and of the objects that it references, __________. a. you are performing a shallow copy b. you are performing a nested copy c. you are performing a deep copy d. a compiler error will occur

C

Which of the following statements correctly specifies two interfaces? a. public class ClassA implements [Interface1, Interface2] b. public class ClassA implements (Interface1, Interface2) c. public class ClassA implements Interface1, Interface2 d. public class ClassA implements Interface1 | Interface2

C

A class becomes abstract when you place the __________ key word in the class definition. a. super b. extends c. final d. abstract

D

If a subclass constructor does not explicitly call a superclass constructor, __________. a. the superclass's fields will be set to the default values for their data types b. Java will automatically call the superclass's default or no-arg constructor immediately after the code in the subclass's constructor executes c. it must include the code necessary to initialize the superclass fields d. Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

D

If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array? a. for (int row = 1; row < numbers.length; row++) { for (int col = 1; col < numbers.length; col++) total += numbers[row][col]; } b. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } c. for (int row = 0; row < numbers[row].length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } d. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

D

In the following code, which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public final int method2(double b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public int method2(double c){} Line 12 } a. Line 4 b. Line 5 c. Line 10 d. Line 11

D

Interfaces can have ________ methods. a. 0 b. 1 c. 2 d. any number of

D

Non-abstract classes are called ________. a. real classes. b. instance classes. c. implementable classes. d. concrete classes.

D

The ArrayList class is in the __________ package. a. java.arraylist b. java.lang \c. java.array d. java.util

D


Set pelajaran terkait

2. HRCI- SPHR Talent Planning & Acquisition

View Set

Lesson Quiz 2-1 Origins of American Government

View Set

Louisiana Life and Health Insurance Exam

View Set

Anatomy final chapters 9, 10, 11, 12

View Set