ITP Final Exam

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

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

Encapsulation

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

False

The Double.parseDouble method converts a double to a string.

False

The following statement correctly creates a StringBuilder object. StringBuilder str = "Tuna sandwich";

False

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

False

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

False

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

False

You can declare an enumerated data type inside a method.

False

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

+

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

-

What will be returned from the following method? public static double methodA() { double a = 8.5 + 9.5; return a; }

18.0

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

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

Random

Which of the following statements will display the maximum value that a double can hold?

System.out.println(Double.MAX_VALUE);

Which of the following statements will print the maximum value an int variable may have?

System.out.println(Integer.MAX_VALUE);

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 would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; }

The value variable will contain the lowest value in the numbers array.

What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 1; i < numbers.length; i++) value += numbers[i];

The value variable will contain the sum of all the values in the numbers array.

If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token.

True

No statement outside the method in which a parameter variable is declared can access the parameter by its name.

True

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

True

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

True

StringBuilder objects are not immutable.

True

The String class's isBlank method returns true if the calling string's length is 0, or it contains only whitespace characters.

True

The String class's regionMatches method performs a case-insensitive comparison.

True

The expression in a return statement can be any expression that has a value.

True

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

True

What will be displayed after the following code is executed? String str = "RSTUVWXYZ"; System.out.println(str.charAt(5));

W

What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder("We have lived in Chicago, Trenton, and Atlanta."); strb.replace(17, 24, "Tampa"); System.out.println(strb);

We have lived in Tampa, Trenton, and Atlanta.

What will the following code display? String str = "xyz".repeat(3).replace("yz", "ab").toUpperCase(); System.out.println(str);

XABXABXAB

To create a method, you must write its ________.

definition

In a @return tag statement the description ________.

describes the return value

What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);

diddl

This method converts a string to an int and returns the int value.

Integer.parseInt

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

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

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

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.

Autoboxing is ________.

Java's process of automatically "boxing up" a value inside an object

Which of the following import statements is required to use the Character wrapper class?

No import statement is required

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

instance fields

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

instance methods

Select all that apply. Which of the following types of values can be passed to a method that has an int parameter variable?

int

Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?

int x = Integer.parseInt(str);

Which of the following statements will convert the string, str = "285" to an int?

int x = Integer.parseInt(str);

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

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

The ________ package is automatically imported into all Java programs.

java.lang

The ArrayList class is in the ________ package.

java.util

What will be displayed after the following code is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26); System.out.println(str2);

jumped

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, which return type should be used for the method?

long[]

Select all that apply. Local variables ________.

lose the values stored in them between calls to the method in which the variable is declared

This String class method adds or takes away spaces from the beginning of each line in a multiline string.

margin

A method ________.

may have zero or more parameters

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

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

numbers[r].length

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

remove

What will be the result after the following code executes? double a = 2.0, b = 2.0, result; result = Math.pow(a, b) + 1;

result will be assigned 5.

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

return type

When using the String class's trim method, a ________ cannot be trimmed.

semicolon

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

semicolon

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

set

Given the following method, which of these method calls is valid? public static void showProduct (int num1, double num2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); }

showProduct(10, 4.5);

Given the following method, which of these method calls is valid? public static void showProduct (double num1, int num2) { double product; product = num1 * num2; System.out.println("The product is " + product); }

showProduct(3.3, 55);

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

state

Instance methods do not have the ________ keyword in their headers.

static

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

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

The header of a value-returning method must specify ________.

the data type of the return value

The process of breaking a problem down into smaller pieces is sometimes called ________.

the divide and conquer method

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

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

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

A series of words or other items of data, separated by spaces or other characters, is known as a ________.

token

The process of breaking a string down into tokens is known as ________.

tokenizing

The ________ character appears at the end (the right side) of a string, after the non-space characters.

trailing whitespace

The ________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted.

trim

The process of converting a wrapper class object to a primitive type is known as ________.

unboxing

The sequential search algorithm ________.

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

What will be the results after the following code is executed? int[] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; }

value contains the lowest value in array1

The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

valueOf

A partially filled array is normally used ________.

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

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}; x = y; y = x;

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

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

you are performing a deep copy

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.

What will be returned from the following method? public static int methodA() { double a = 8.5 + 9.5; return a; }

This is an error.

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

Most of the String comparison methods are case sensitive.

True

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

True

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

Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

String str = Integer.toString(number);

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.

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

Instance methods do not have the keyword static in their headers.

True

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

True

Methods are commonly used to break a problem into small manageable pieces.

True

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

True

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

True

What will be displayed after the following code is executed? String str = "abc456"; for (int i = 0; i < str.length(); i++) { char chr = str.CharAt(i); if (!Character.isLetter(chr)) System.out.print(Character.toUpperCase(chr)); }

456

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.

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

False

If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

False

If a class has mutator methods, it is probably an immutable class.

False

If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is returned.

False

If an immutable class has a mutable object as a field, it is permissible for a method in the immutable class to return a reference to the mutable field.

False

In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

Java limits the number of dimensions that an array can have to 15.

False

Only constants and variables may be passed as arguments to methods.

False

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

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 class specifies the ________ and ________ that a particular type of object has.

fields, methods

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

final

This String class method returns true if the calling String object contains a specified substring.

isOwnerOf

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.

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

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}

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

"has a"

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.lastIndexOf("ov", 14);

-1

By default, Java initializes array elements to ________.

0

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

0

Subscripting always starts with ________.

0

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

1

What are the tokens in the following code? String str = "123-456-7890"; String[] tokens = str.split("-");

123, 456,7890

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.indexOf("ov");

15

________ 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

Local variables can be initialized with ________.

Any of these.

A value-returning method must specify ________ as its return type in the method header.

Any valid data type

CRC stands for ________.

Class, Responsibilities, Collaborations

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

False

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

False

Instance methods should be declared static.

False

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.

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.

Each of the numeric wrapper classes has a static ________ method that converts a number to a string.

ToString

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

True

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

True

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 parameter variable's scope is the method in which the parameter is declared.

True

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

True

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

True

A value-returning method can return a reference to a non-primitive type.

True

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

True

An enumerated data type is actually a special type of class.

True

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

True

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

True

Trying to extract more tokens than exist from a StringTokenizer object will cause an error.

True

Two general categories of methods are void methods and value-returning methods.

True

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

True

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

True

When working with the String and StringBuilder classes' getChars method, the character at the start position is included in the substring but the character at the end position is not included.

True

You can change the contents of a StringBuilder object, but you cannot change the contents of a String object.

True

You must have a return statement in a value-returning method.

True

enum constants have a toString method.

True

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

In a general sense, a method is ________.

a collection of statements that perform a specific task

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

a compiler error will occur

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

In the following code, Math.Pow(a, b) is an example of ________. double a = 2.0, b = 2.0, result; result = Math.pow(a, b) + 1;

a value-returning method

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

a wildcard import statement

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

add

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

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

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

an explicit import statement

All @param tags in a method's documentation must ________.

appear after the general description of the method

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

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

array's data type

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

Which of the following statements will convert the string, str = "285.74" to a double?

double x = Double.parseDouble(str);

A declaration for an enumerated type begins with the ________ key word.

enum

If str is declared as: String str = "ABCDEFGHI"; What will be returned from the following statement? Character.toLowerCase(str.charAt(5))

f

What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str1); System.out.println(matches);

false

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

fields private

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

If numbers are 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]; }

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

A class whose internal state cannot be changed is known as a(n) ________ class.

immutable

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

in order to avoid having stale data

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

inner class

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

instance

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

This String class method returns true if the calling string's length is 0, but returns false if the calling string contains only whitespace characters.

isEmpty

When an argument is passed to a method ________.

its value is copied into the method's parameter variable

A class that provides mutators to change the values of the class's fields is known as a(n) ________ class.

mutable

Is the following class mutable or immutable? public final class Status { private String code; public Status(String c){code = c; } public void setCode(String c) { code = c; } public String getCode() { return code; } }

mutable

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 lifetime of a method's local variable is ________.

only while the method is executing

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

package

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

parentheses

A constructor is a method that ________.

performs initialization or setup operations

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

primitive variable

All fields in an immutable class should be declared ________.

private and final

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

public static void passArray(int [][])

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

public static void passMyArray(int[][])

What will be displayed after the following statements are executed? String str = "red$green&blue#orange"; String[] tokens = str.split("[$&#]"); for (String s : tokens) System.out.print(s + " ");

red green blue orange

Static methods can only operate on ________ fields.

static

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

subscript

The term ________ commonly is used to refer to a string that is part of another string.

substring

The term ________ is commonly used to refer to a string that is part of another string.

substring

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

the method has access to the object that the variable references

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

Which type of method performs a task and sends a value back to the code that called it?

value-returning

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

void

Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public double finalOrderTotal() { return orderAmount - orderAmount * orderDiscount; } } public class CustomerOrder {public static void main(String[] args) { Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(orderNumber, orderAmt, orderDisc); double finalAmount = order.finalOrderTotal(); System.out.printf("Final order amount = $%,.2f\n", finalAmount); } }

522.00

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

A class's responsibilities include ________.

both of these

After the header, the body of the method appears inside a set of ________.

braces, { }

Methods are commonly used to ________.

break a program down into small manageable pieces

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

class, object

You can concatenate String objects by using the ________.

concat method or the + operator

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

In the following code, how many times will the for loop execute? String str = "1,2,3,4,5,6,7,8,9"); String[] tokens = str.split(","); for (String s : tokens) System.out.println(s);

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

When writing documentation comments for a method, you can provide a description of each parameter by using a ________.

@param tag

To document the return value of a method you can use a ________.

@return tag

What will be printed after the following code is executed? String str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); m++; }

ABC

If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.

True

Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public int getOrderAmount() { return orderAmount; } public int getOrderDisc() { return orderDisc; } } public class CustomerOrder { public static void main(String[] args) { int ordNum = 1234; double ordAmount = 580.00; double discountPer = .1; Order order; double finalAmount = order.getOrderAmount() - order.getOrderAmount() * order.getOrderDisc(); System.out.printf("Final order amount = $%,.2f\n", finalAmount); } }

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

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

Tree.PINE

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

Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.

True

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

Constants, variables, and the values of expressions may be passed as arguments to a method.

True

Declaring an array reference variable does not create an array.

True

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.

True

What will the following code display? String str = "a".repeat(3).replace("a", "z").toUpperCase(); System.out.println(str);

ZZZ

In the following code, System.out.println(num) is an example of ________. double num = 5.4; System.out.println(num); num = 0.0;

a void method

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?

account20.getNumberOfAccounts();

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

actually a reference to the object that is passed


Ensembles d'études connexes

The Framework for Consumer Analysis

View Set

Sepoy Rebellion, Indian Independence, and British Imperialism

View Set

Introduction to Personality and Psychodynamic Theories

View Set

Chapter 39: Nursing Care of the Child With an Alteration in Sensory Perception/Disorder of the Eyes or Ears

View Set