Comp Sci 5-6

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

A. True

You can declare an enum in a separate java file

dive must be a method.

submarine.dive(depth);

ordinal

Enumerated types have the __________ method which returns the position of an enum constant in the declaration list.

False

Every Java class must have a method main()

diskOut.println("Calvin");

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt?

t

If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

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

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

default equals is same as ==

If you do not write an equals method for a class, Java provides one. Describe the behavior of the equals method that Java automatically provides.

SavingsAccount.getNumberOfAccounts();

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?

t

If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.

False

In a Java program a method that does not return anything can either have a return type of void or have no return type listed at all.In a Java program a method that does not return anything can either have a return type of void or have no return type listed at all.

f

In a for loop, the control variable is always incremented.

t

Java does not limit the number of dimensions an array may have.

variable-length argument list

Java provides a mechanism known as a __________ which makes it possible to write a method that takes a variable number of arguments

sentinel

A __________ is a value that signals when the end of a list of values has been reached.

post test

A __________ loop will always be executed at least once.

True

A class method has access to all instance fields even if they are declared private.

t

A class's static methods do not operate on the fields that belong to any instance of the class.

True

A constructor is typically used to construct objects of a particular class type, whereas methods are typically used to define operations appropriate to a particular class type.

False

A default constructor is provided by Java for every class implemented by a user even if the user has defined his own arg constructor

the method name and the parameter list

A method's signature consists of

true

A static member method must refer to static member variables of the same class.

false

Adding a byte variable to a short variable will upgrade the byte variable to short first, perform the addition, and give a result as a short since short has higher rank compared to byte.

consists of an array of references to String objects

An array of String objects

t

An instance of a class does not have to exist in order for values to be stored in a class's static fields.

f

The key word this is the name of a reference variable that an object can use to refer to its method.

while (inputFile.hasNext())

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?

set the accumulator variable to an initial value, often zero

Before entering a loop to compute a running total, the program should first

Class, Responsibilities, Collaborations

CRC stands for

false

The default behavior of equals() method of any object is to compare the two objects field by field to determine whether they are equal.

f

The for loop is a posttest loop that has built-in expressions for initializing, testing, and updating.

having two or more methods with the same name but different signatures

Overloading is

False

Run-time error occurs when your code is running as expected but is giving the wrong answers.

f

The Java compiler will display an error message when it processes a statement that uses an invalid subscript

t

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line

f

The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

False

The only case in which shadowing occurs is if the parameters of an instance method share the same identifier with a class field

they cannot refer to nonstatic members of the class

The only limitation that static methods have is

F

The while loop is always the best choice in situations where the exact number of iterations is known.

t

To determine if two arrays are equal you must compare each of the elements of the two arrays

use the toString method

To get the name of a calling enum constant

210

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; y += 20; }

f

When an array of objects is declared but not initialized, the array values are set to 0.

t

When an object is passed as an argument, it is actually a reference to the object that is passed

t

When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration

it must be the first statement in the constructor making the call

When the this variable is used to call a constructor

t

You can use the PrintWriter class to open a file and write data to it

a case expression

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


Ensembles d'études connexes

6. Share Data Through the Art of Visualization

View Set

Retirement Plan Fundamentals: Module 1: Lifecycle of a Plan

View Set

ECON 211 - Homework 3 (CH. 10 - 13)

View Set

Uprep Electrolytes/ acid base balance/ fluids

View Set