COSC-2403 FINAL REVIEW

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, or int y not equal to 1000?

((x <= 500 || x > 650) && !(y == 1000))

In the header, the method name is always followed by ________.

parentheses

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

add

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"

Values that are sent into a method are called ________.

arguments

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

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

final

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

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

To return an array of long values from a method, which return type should be used for the method?

long[]

A method ________.

may have zero or more parameters

A reference variable stores a(n) ________.

memory address

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

methods

f 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 will format 12.78 to display as 12.8%?

System.out.printf("%.1f%%", 12.78);

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

((x > 500 && x < 650) || (y != 1000))

What will be the value of x after the following code is executed?int x, y = 15;x = y--;

15

What will be the value of x after the following code is executed?int x, y = 4, z = 6;x = (y++) * (++z);

28

What will be the values of x and y after the following code is executed?int x, y = 15, z = 3;x = (y--) / (++z);

3

What is the value of z after the following code is executed?int x = 5, y = 28;float z;z = (float) (y / x);

5.0

If you don't provide an access specifier for a class member, the class member is given ________ access by default.

package

A constructor is a method that ________.

performs initialization or setup operations

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

polymorphic

A ________ loop will always be executed at least once.

posttest

A subclass may call an overridden superclass method by ________.

prefixing its name with the super key word and a dot ( .)

When declaring class data members it is best to declare them as ________.

private members

The scope of a public instance field is ________.

the instance methods and methods outside the class

The scope of a private instance field is ________.

the instance methods of the same class

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

the method has access to the object that the variable references

When you pass an argument to a method you should be sure that the argument's type is compatible with ________.

the parameter variable's data type

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

the program will terminate

In an inheritance relationship ________.

the superclass constructor always executes before the subclass constructor

The sequential search algorithm ________.

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

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

using the private access specifier on the class fields

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

"has a"

Protected class members can be denoted in a UML diagram with the ________ symbol.

#

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

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 does the following code display?double x = 12.3798146;System.out.printf("%.2f\n", x);

12.38

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

"Has a"

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

Any of these

Given the following code, which statement is true?

ClassB must override each method in ClassA.

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Control is returned to method C.

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

Encapsulation

What does the following statement do?double[] array1 = new double[10];

It does all of these.

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

Assume the class BankAccount has been created and the following statement correctly creates an instance of the class.

The account object's toString method will be implicitly called.

What is required for an interface method that has a body?

The method header must begin with the key word default.

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.

Which of the following is not true about static methods?

They are called from an instance of the class.

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

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

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 Java, when a character is stored in memory, it is actually the ________ that is stored.

Unicode number

When a method tests an argument and returns a true or false value, it should return ________.

a boolean value

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

a case expression

If you attempt to use a local variable before it has been given a value, ________.

a compiler error will occur

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

A ragged array is ________.

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

In the following code, System.out.println(num) is an example of ________.

a void method

In all but very rare cases, loops must contain, within themselves ________.

a way to terminate

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

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

When an "is a" relationship exists between objects, the specialized object has ________.

all of the characteristics of the general object plus additional characteristics

If a class contains an abstract method ________.

all of these

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

an explicit import statement

A protected member of a class may be directly accessed by ________.

any of these

Local variables can be initialized with ________.

any of these

Values stored in local variables ________.

are lost between calls to the method in which they are declared

All fields declared in an interface ________.

are treated as final and static

Given the following method header, which of these method calls is incorrect?public void displayValue(double x, int y);

displayValue(a, b); // where a is a short and b is a long

Given the following method header, which of these method calls is incorrect?public void displayValue(int x, int y);

displayValue(a, b); // where a is a short and b is a long

The ________ loop is ideal in situations where you always want the loop to iterate at least once.

do-while

Which key word indicates that a class inherits from another class?

extends

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

fields private

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

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

The ________ loop is ideal in situations where the exact number of iterations is known.

for

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 the operator used to determine whether an object is an instance of a particular class?

instanceOf

Which of the following is an example of a lambda expression?

int x = x * factor;

A deep copy of an object ________.

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

A search algorithm ________.

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

When an argument is passed to a method ________.

its value is copied into the method's parameter variable

The ________ package is automatically imported into all Java programs.

java.lang

To compile a program named First you would use which of the following commands?

javac First.java

Which of the following cannot be used as identifiers in Java?

key words

________ is a special type of expression used to create an object that implements a functional interface.

lambda

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

length

Which of the following expressions will generate a random number in the range of 1 through 10?

myNumber = randomNumbers.nextInt(10) + 1;

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

numbers[r].length

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 subclass can directly access ________.

only public and protected members of the superclass

The lifetime of a method's local variable is ________.

only while the method is executing

If two methods have the same name but different signatures they are ________.

overloaded

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.

overrides

A group of related classes is called a(n) ________.

package

A ________ member's access is somewhere between public and private.

protected

All methods specified by an interface are ________.

public

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

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

Instance methods do not have the ________ key word in their headers.

static

Static methods can only operate on ________ fields.

static

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)

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();

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

string

When the + operator is used with strings, it is known as the ________.

string concatenation operator

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

super

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 header of a value-returning method must specify ________.

the data type of the return value

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

the method does not have access to the original array

A parameter variable's scope is ________.

the method in which the parameter is declared

A UML diagram does not contain ________.

the object names

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

the object's memory address

The only limitation that static methods have is ________.

they cannot refer to nonstatic members of the class

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

they have different parameter lists

Which of the following is true?

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

An expression tested by an if statement must evaluate to ________.

true or false

A ________ type of method performs a task and then terminates.

void

Which of the following are pre-test loops?

while, for

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

whole-part relationship

The binary search algorithm ________.

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

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

What does the following code display?int d = 9, e = 12;System.out.printf("%d %d\n", d, e);

9 12

________ tells the Java compiler that a method is meant to override a method in the superclass.

@Override

What would be displayed as a result of executing the following code?final int x = 22, y = 4;y += x;System.out.println("x = " + x + ", y = " + y)

Nothing. There is an error in the code.

Which of the following is true about protected access?

Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

Which of the following statements will create an object from the Random class?

Random myNumber = new Random();

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();

________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.

Short-circuit evaluation

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

String str = "Hello, World";

When a subclass overloads a superclass method ________.

both methods may be called with a subclass object

If you prematurely terminate an if statement with a semicolon, the compiler will ________.

both not display an error message and assume you are placing a null statement there

Methods are commonly used to ________.

break a program down into small manageable pieces

Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree?

class hierarchy

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

When an argument value is passed to a method, the receiving parameter variable is ________.

declared in the method header inside the parentheses

When an array is passed to a method ________.

All of these are true

A class becomes abstract when you place the ________ key word in the class definition.

abstract

A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass.

abstract

When an object, such as a String, is passed as an argument it is ________.

actually a reference to the object that is passed

Which of the following is not a part of a method call?

return type

To compare two objects in a class, ________.

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

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

Which of the following statements will correctly convert the data type, if x is a float and y is a double?

x = (float)y;

What will be the values of x and y as a result of the following code?int x = 25, y = 8;x += y++;

x = 33, y = 9

What output will be displayed as a result of executing the following code?int x = 5, y = 20;x += 32;y /= 4;

x = 37, y = 5

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

you are performing a deep copy


Conjuntos de estudio relacionados

Life and Death Decisions Midterm 2

View Set

CBA-396 International Business Test #3 JSU (Lenn Rainwater)

View Set

CH 4: Discounted Cash Flow Valuation

View Set

AP Biology: Plats, Chapter 11 - The Leaf

View Set

Critical Care: Chapter 19: Endocrine Alterations

View Set

Women during the French Revolution

View Set

History of Graphic Design Exam 1

View Set

Module 2.10: Mutual Funds and Other Investments

View Set

Semester #1, Unit #2 Multiple Choice Study Guide- A.P. Biology

View Set