Exam 2 review multiple choice

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

It is common practice to use a __________variable as a size declarator.

final

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;}

180

What does <String> specify in the following statement?ArrayList<String> nameList = new ArrayList<String>();

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

If a subclass constructor does not explicitly call a superclass constructor, __________.

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

What is wrong with the following code?public class ClassB extends ClassA { public ClassB() {int init = 10; super(40);} }

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

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9];

The numbers array has 6 rows and 9 columns.

What type of relationship exists between two objects when one object is a specialized version of another object?

"is a"

Which expression adds 1 to the element of array arrayName at index i?

++arrayName[i].

Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the ordinal value of the MAPLE enum constant?

1

When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?

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

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 UML diagram

a ragged array is ________.

a two-dimensional array where the rows have different numbers of columns

A class becomes abstract when you place the __________ keyword in the class definition.

abstract

The ___________ method is used to insert an item into an ArrayList.

add

When a method is declared with the __________ modifier, it cannot be overridden in a subclass.

fianl

Every object in Java knows its own class and can access this information through method

getClass

All methods specified by an interface are __________.

public

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

The __________ key word is used to call a superclass constructor explicitly.

super

In order to do a binary search on an array __________.

the array must first be sorted

In an inheritance relationship __________.

the superclass constructor always executes before the subclass constructor

The only limitation that static methods have is __________.

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];}

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, __________.

you are performing a deep copy

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

ClassB

Given the following code, which statement is true?public class ClassB implements ClassA{ }

ClassB must override each method in ClassA.

Assigning a subclass reference to a superclass variable is safe________.

because the subclass object is an object of its superclass.

Non-abstract classes are called ________.

concrete classes

Interfaces can have ________ methods.

any number of

private fields of a superclass can be accessed in a subclass

by calling public or protected methods declared in the superclass.

If the superclass contains only abstract method declarations, the superclass is used for ________.

interface inheritance.

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 }

Line 11

__________ is the term for the relationship created by object aggregation.

"Has a"

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;}

60

Every class in Java, except ________, extends an existing class.

Object

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?

for (int row = 0; row < numbers.length; row++) {for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col];}

The ArrayList class is in the __________ package.

java.util

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?

numAccounts = SavingsAccount.numberOfAccounts;

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passMyArray(int[][])

The __________ method removes an item from an ArrayList at a specific index.

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.

str[0].toUpperCase();

When a reference variable is passed as an argument to a method __________.

the method has access to the object that the variable references


Kaugnay na mga set ng pag-aaral

America, a narrative history,ch. 30

View Set