Exam 2 Review 4305

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

" Has a "

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

ClassB

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 two-dimensional array where the rows have different numbers of columns

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

abstract

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.

by calling public or protected methods declared in the superclass.

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

final

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

getClass.

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

java.util

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

public

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

Object

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

"is a"

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

1 Count by 0, 1, 2 so maple is 1

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

180

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

60 5*8 + 20

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

Add

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.

ClassB must override each method in ClassA

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

Final

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.

It specifies that only String objects may be stored in the ArrayList object.

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.

The call to the method super must be the first statement in the constructor.

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

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

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

Line 11

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

Super

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.

The numbers array has 6 rows and 9 columns.

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.

The program compiles and runs because the instance variables are initialized to their default values.

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.

This is a public method that accepts a Stock object as its argument and returns a boolean value.

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

a UML diagram

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

any number of

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.

because the subclass object is an object of its superclass.

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

the method has access to the object that the variable references

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

concrete classes.

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. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

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

interface inheritance

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;

numAccounts = SavingsAccount.numberOfAccounts;

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

public class ClassA implements Interface1, Interface2

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)

public static void passMyArray(int[][])

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

remove

Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement. a. str.uppercase(); b. str[0].upperCase(); c. str.toUpperCase(); d. str[0].toUpperCase();

str[0].toUpperCase();

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

the array must first be sorted

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

the superclass constructor always executes before the subclass constructor

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

they cannot refer to nonstatic members of the class

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.

value contains the sum of all the values in array1.

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

you are performing a deep copy


Ensembles d'études connexes

Human Anatomy and Physiology CHAPTER 2, Human anatomy and physiology Exam 3, Human Anatomy and Physiology Tissue Review, Human Anatomy and Physiology Review, Essentials of Human Anatomy and Physiology, Human Anatomy and Physiology Lab, TEAS Human Ana...

View Set

Wrist and Hand Fractures/Pathologies

View Set

Chapter 4 Eukaryotic Cells and Microorganisms Whi

View Set

Insurance Exam Practice Questions

View Set

CNA 210 | Ch. 9, Client and Application Security

View Set