Computer Science Exam 3

Ace your homework & exams now with Quizwiz!

Subscripting always starts with ________.

0

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.

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

a wildcard import statement

The java.lang package is automatically imported into all Java programs.

True

When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.

True

When an object reference is passed to a method, the method may change the values in the object.

True

The ________ indicates the number of elements the array can hold.

arrays data type

A sorting algorithm is used to locate a specific item in a larger collection of data.

False

If a[] and b[] are two integer arrays, the expression a == b compares the array contents

false

It is common practice to use a ________ variable as a size declarator.

final

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

garbage collection

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

private members

An object's ________ is simply the data that is stored in the object's fields at any given moment.

state

Static methods can only operate on ________ fields.

static

A UML diagram does not contain ________.

the object names

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

the program will terminate

The binary search algorithm ________.

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

Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.

true

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of ________.

a chain of inheritance

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

they have different parameter lists

By default, Java initializes array elements to ________.

0

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

fields private

You can use the ________ method to replace an item at a specific location in an ArrayList.

set

A(n) ________ is used as an index to pinpoint a specific element within an array.

subscript

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

the array must first be sorted

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

the code

A class is not an object. It is a description of an object.

True

An object can store data

True

You can write a super statement that calls a superclass constructor but only in the subclass's constructor.

True

A class that is defined inside another class is called a(n) ________.

inner class

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

A UML diagram

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

Protected

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

An access specifier indicates how a class may be accessed.

True

Objects in an array are accessed with subscripts, just like any other data type in an array.

True

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

a whole number, a reference to an object, and a string of characters

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

Overloading means that multiple methods in the same class ________.

have the same name but different parameter lists

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

overloaded

To indicate the data type of a variable in a UML diagram, you enter ________.

the variable name followed by a colon and the data type

A partially filled array is normally used ________.

with an accompanying integer value that holds the number of items stored in the array

To compare two objects in a class, ________.

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

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

+

A method that gets a value from a class's field but does not change it is known as a mutator method.

False

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

False

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

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

Any items typed on the command line, separated by a space, after the name of the class are considered to be one or more arguments that are to be passed into the main method

True

Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.

True

Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones.

True

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

True

Methods that operate on an object's fields are called ________.

instance methods

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

objects

hat does specify in the following statement?

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

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

String str = "Hello, World";

The scope of a private instance field is ________.

the instance methods of the same class

An abstract class is not instantiated itself but serves as a superclass for other classes

True

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

length

A single copy of a class's static field is shared by all instances of the class.

True

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

True

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

True

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

ClassA

The key word this is the name of a reference variable that is available to all static methods.

false

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

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

methods

One or more objects may be created from a(n) ________.

class

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

instance

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

class hierarchy

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

"is a"

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.

The term "default constructor" is applied to the first constructor written by the author of the class.

False

It is not possible for a superclass to call a subclass's method.

True

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

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

public static void passMyArray(int[][])

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

the method does not have access to the original array

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

0

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

A class's responsibilities include ________.

The things a class is responsible for knowing and the things a class is responsible for doing.

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

super

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

true

A search algorithm ________.

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

The ArrayList class is in the ________ package.

java.util

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

A class specifies the ________ and ________ that a particular type of object has.

fields, methods

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;

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

static

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

the method has access to the object that the variable references

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 a class hierarchy ________.

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom

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

final

A constructor ________.

has the same name as the class

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

long []

Instance methods should be declared static.

False

Select all that apply. Which of the following statements is(are) true about this code?final int ARRAY_SIZE = 10;long[] array1 = new long[ARRAY_SIZE];

It creates an instance of an array of ten long values.

When an array is passed to a method ________.

It is passed just as any other object would be passed, the methods has direct access to the original array, a reference to the array is passed.

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

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

True

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

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"

Declaring an array reference variable does not create an array.

True

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.

True

If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent:System.out.println(object1);System.out.println(object1.toString());

True

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

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

True

The term "no-arg constructor" is applied to any constructor that does not accept arguments.

True

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

True

The only limitation that static methods have is ________.

they cannot refer to nonstatic members of the class

When a subclass extends a superclass, the public members of the superclass become public members of the subclass.

True

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

True

A reference variable stores a(n) ________.

memory address

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

public class Salaried extends PayType

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 limits the number of dimensions that an array can have to 15.

False

The public access specifier for a field indicates that the field may not be accessed by statements outside the class.

False

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.

A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.

True

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

methods of the same class, methods of a subclass, and methods in the same package

Most of the programming languages used today are ________.

object-oriented

When a field is declared static there will be

only one copy of the field in memory

The scope of a public instance field is ________.

the instance methods and methods outside the class

All methods in an abstract class must also be declared abstract.

False

An array can hold multiple values of several different types of data simultaneously.

False

If two methods in the same class have the same name but different signatures, the second overrides the first.

False

In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

False

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.

False

Once an array is created, its size cannot be changed.

True

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

@override

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

-

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

Package

Select all that apply. Which of the following are classes from the Java API?

PrintWriter

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 a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.

True

A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final.

True

A constructor is a method that is automatically called when an object is created.

True

An ArrayList object automatically expands in size to accommodate the items stored in it.

True

Every class has a toString method and an equals method inherited from the Object class.

True

If a class contains an abstract method ________.

You must create an instance of the class, the. method will only have a header, but not a body and will end with a semicolon, and the method cannot be overridden in subclasses.

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

in order to avoid having stale data

In Java, you do not use the new operator when you use a(n) ________.

initialization list

When an object is created, the attributes associated with the object are called ________.

instance fields

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;

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

numbers[r].length

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.p

polymorphic

A subclass may call an overridden superclass method by ________.

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

When you work with a ________, you are using a storage location that holds a piece of data.

primitive variable

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

public static void passArray(int [][])

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

remove

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

the objects memory address

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

true

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

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

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.

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

#

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

What would be the result of executing the following code?int[] x = {0, 1, 2, 3, 4, 5};

An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.

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

ClassB

A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

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

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?

add

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

all of the characteristics of the general object plus additional characteristics

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

an explicit import statement

A subclass can directly access ________.

only public and protected members of the superclass

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

A constructor is a method that ________.

performs initialization or setup operations

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

extends

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

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

When the this variable is used to call a constructor ________.

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

In an inheritance relationship ________.

the superclass constructor always executes before the subclass constructor

Which of the following is not true about static methods?

they are called from an instance of the class

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

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

Encapsulation

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

True

When a subclass overloads a superclass method ________.

both methods may be called with a subclass object

Replacing inadequate superclass methods with more suitable subclass methods is known as ________.

method overriding

The sequential search algorithm ________.

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


Related study sets

Chapter 14 Principles of Disease and Epidemiology

View Set

Chapter 1 (Art in the Stone Age)- multiple choice quiz questions

View Set

Geografija 6 - Australija, Arktik i Antarktika

View Set

Worksheet 18.1: Nature and Classification

View Set

BIET Topic 4: Thermometers and Temperature Conversion

View Set

Chapter 11: Determining Cost of Capital

View Set

Psychology Module 16 Study Guide

View Set