COSC 2403 Exam 2

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

When an array is passed to a method _. It is passed just as any other object would be passed The method has direct access to the original array A reference to the array is passed

All of these are tru

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.

For the following code, which statement is not true public class Sphere { private double radius; public double x; private double y; private double z; }

The z field is available to code written outside the Sphere class

Given the following declaration: enum Tree (OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant?

Tree.PINE

The whole-part relationship created by object aggregation is more often called a(n) ________ relationship.

"has a"

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

"has a"

_ refers to combining data and code into a single object.

Encapsulation

A deep copy of an object _.

Is an operation that copies an aggregate object and all the objects that it references

What does the following statement do? Double [] array1 = new double[10]; It declares array1 to be a reference to an array of double values. It creates an instance of an array of ten double values. It does all of these. It will allow valid subscripts in the range of 0 through 9.

It does all of these.

Which of the following is not true about static methods?

It is necessary for an instance of the class to be created to execute the method.

Class objects normally have _ that perform useful operations on their data, but primitive variables do not.

Methods

If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method?

SavingsAccount.getNumberOfAccounts();

Java allows you to create objects of the _ class in the same way you would create primitive variables

String

Which of the following statements will create a reference, str, to the String "Hello, World"?

String str = "Hello, World";

Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account);

The account object's toString method will be implicitly called

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for (I = 1; I <= ARRAY_SIZE: I++) { x[I] = 10.0; }

The code contains a syntax error and will not compile

The scope of a private instance field is _.

The instance methods of the same class

When an individual element of an array is passed to a method.

The method does not have access to the original array

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

For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }

The y field is available to code written outside the Circle class

If the following is from the method section of a UML diagram, which of the following statements is true? + equals(object2:Stock) : boolean

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

The sequential search algorithm _.

Uses a loop to sequentially step through an array, starting with the first element

The binary search algorithm _.

Will cut the portion of the array being searched in half each time the loop fails to locate the search value

You cannot use the fully-qualified name of an enum constant for ________.

a case expression

If the this variable is used to call a constructor, _.

a compiler error will result if it is not the first statement of the constructor

What does the following UML diagram entry mean? + setHeight(h : double) : void

a public method with a parameter of data type double that does not return a value

When a method's return type is a class, what is actually returned to the calling program?

a reference to an object of that class

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String object containing "ghi"

A ragged array is _.

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

In Java it is possible to write a method that will return ________.

a whole number a reference to an object a string of characters Any of these

The _ method is used to instert an item into an ArrayList

add

The following statement is an example of _. import java.util.Scanner;

an explicit import statement

Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

array bounds checking

A(n) _ can be thought of as a blueprint that can be used to create a type of _.

class, object

In memory, an array of String objects _.

consists of an array of references to String objects

The JVM periodically performs the ________ process to remove unreferenced objects from memory.

garbage collection

A constructor _

has the same name as the class

Overloading means that multiple methods in the same class _.

have the same name but different parameter lists

You should not define a class that is dependent on the values of other class fields _.

in order to avoid having stale data

Another term for an object of a class is a(n)

instance

Which of the following is a valid declaration for a ragged array with five rows but no columns?

int[][] ragged = new int[5][];

A search algorithm _.

is used to locate a specific item in a collection of data.

The _ package is automatically imported into all Java programs.

java.lang

Each array in Java has a public field named _ that contains the number of elements in the array.

length

To return an array of long values from a method, use this as the return type for the method.

long []

A reference variable stores a(n)

memory address

You cannot use the == operator to compare the contents of ________.

objects

When a field is declared static there will be ________.

only one copy of the field in memory

A group of related classes is called a(n)

package

A constructor is a method that _

performs initialization or setup operations

Which of these classes compile and use a default constructor? (Choose all that apply)

public class Bird { } public class Bird { public Bird() {} } public class Bird { void Bird() { }

Which of the following methods compile? (Choose all that apply)

public void methodA() { return;} public void methodD() {} public int methodD() { return 9;} public double methodE() { return 9;}

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

remove

Instance methods do not have the _ key words in their headers

static

Static methods can only operate on ________ fields.

static

Given the following method header, what will be returned from the method? public Rectangle getRectangle()

the address of an object of the Rectangle class

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

the array must first be sorted

The scope of a public instance field is _.

the instance methods and methods outside the class

A UML diagram does not contain

the object names

Which of the following is true?

this.variableName can be called from any instance method in the class

Data hiding( which means that critical data stored inside the object is protected from the code outside the object) is accomplished in Java by _.

using the private access specifier on the class fields

The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.

whole-part relationship

If object1 and object2 are objects of the same class, to make object2 a copy of object1 ________.

write a method for the class that will make a field by field copy of object1 data members into object2 data members

To compare two objects in a class, ________.

write an equals method that will make a field by field compare of the two objects

What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

Which symbol indicates that a member is public in a UML diagram?

+

Which symbol indicates that a member is private a UML diagram?

-

Java automatically stores a ________ value in all uninitialized static member variables.

0

When an object is passed as as an argument to a method, what is passed into the method's parameter variable?

The object's memory address

Given the following code, what will be the value of finalAmount when it is displayed?

There is no value because the object, order, has not been created.

Which of the following is not true about static methods?

They are called from an instance of the class.

Two or more methods in a class may have the same name as long as _.

They have different parameter lists.

If the following is from the method section of a UML diagram, which of the following statements is true? + equals(object2:Stock) : boolean

This is a public method named add that accepts and returns references to objects in the Stock class

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

If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

numbers[r].length

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

public static void passMyArray(int[][])

If you attempt to perform an operation with a null reference variable _.

the program will terminate

The only limitation that static methods have is ________.

they cannot refer to nonstatic members of the class

When you make a copy of the aggregate object and of the objects that it references, ________.

you are performing a deep copy

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0 through 14

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

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

180

How many compiler error are in the following code?

2

Given the following code, what will be the value of finalAmount when it is displayed?

522.00

It is common practice in object-oriented programming to make all of a class's _

fields private

Which of the following can fill in the blank in this code to make it compile? (Choose all that apply) public class Ant { _____ void method() { } }

final private

Which of the following compile? (Choose all that apply)

final static void method4(){} static final void method3(){}

Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};

for (int I = 0; I < names.length; I++) System.out.println(names[I].length());

What is the result of the following program?

9

What is the value of scores[2][3] in the following array? int[][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };

94

A static field is created by placing the key word static _.

After the access specifier and before the field's data type

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

numAccounts = SavingsAccount.numberofAccounts;

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


Set pelajaran terkait

Prep U: Chapter 15: Postpartum Adaptations

View Set

Chapter 11 Review Perfect Competition

View Set

Warranty Basics for Technicians and Profile Administrators (RWSW112)

View Set