Starting Out with Java Chapters 8 - 11

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

int[] x = {22, 33, 44}; arrayProcess(x[1]); ... public static void arrayProcess(int a) { a = a + 5; }

33

What will be the value of x[8] after the following code has been 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

For the following code, how many times would the while loop execute? StringTokenizer strToken = new StringTokenizer('Ben and Jerry's ice cream is great.'); while (strToken.hasMoreTokens) { System.out.println(strToken.nextToken()); }

7

For the following code, how many times would the loop execute? StringTokenizer strToken = new StringTokenizer("Cars, trucks, and SUVs are all types of automobiles."); while(strToken.hasMoreTokens) { System.out.println(strToken.nextToken()); }

9

What eill be the value of matches after the following code has been executed> boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon'; matches = str1.endsWith(str2);

False

When an interface variable references an object you can use the interface variable to call all the methods in the class implementing the interface.

False

The following StringBuffer constructor will StringBuffer str = new String Buffer(25)

Give the object, str, 25 bytes of storage and not store anything in them

The term for the relationship created by object aggregation is

Has a

When you are writing with string objects that may have unwanted spaces at the beginning or end of the strings, use the ____ method to delete them.

trim

If you are using characters other than whitespaces as delimeters, 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

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

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

True

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

True

StringBuffer objects are not immutable.

True

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

True

The valueOf() method accepts a value of any primitive data type as an argument and returns a string representation of the value.

True

What will be the value of matches after the following code is executed? boolean matches; String[] productCodes = {"456HI345", "3456hj"}; matches = productCodes[0].regionMatches(true, 1, productCode[1], 2, 3)

True

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

True

Two ways of concatenating two strings are

Use the concat() method or use the + between the two Strings

The sequential search algorithm

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

What would be the results of the following code? 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

If String str = "RSTUVWXYZ", what will be the value returned from str.charAt(5)?

W

What will be the value of strbuff after the following statements are executed? StringBuffer strbuff = new StringBuffer('We have lived in Chicago, Trenton, and Atlanta." strbuff.replace(26,33,"Tampa");

We have lived in Chicago, Tampa, and Atlanta.

What will be the value of strbuff after the following statements are executed? StringBuffer strbuff = new StringBuffer('We have lived in Chicago, Trenton, and Atlanta." strbuff.replace(17,24,"Tampa");

We have lived in Tampa, Trenton, and Atlanta.

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

In UML diagrams, inheritance is shown

With a line that has an open arrowhead at one end that point to the base class

In UML diagrams, inheritance is shown

With a line that has an open arrowhead at one end that points to the superclass

To copy an object to another object of the same class

Write a copy method that will make a field by field copy of the two objects

To compare two objects

Write an equals method that will make a field by field comparison of the two object

You can use this ArrayList class method to replace an item at a specific location in anArrayList.

set

What would be the results of executing the following code? StringBuffer str = new String Bufffer("Little Jack Horner") str.append("sat on the"); str.append("corner");

str would equal " Little Jack Horner sat on the corner"

Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement

str[0].toUpperCase();

What would be the results of executing the following code? StringBuffer strbuff = new StringBuffer(12); strbuff.append("The cow"); strbuff.append("jumped over the"); strbuff.append("moon");

strbuff would equal "The cow jumped over the moon"

What would be the results of the following code? 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

What would be the results after the following code was 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}

What would be the results after the following code was 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}

You can declare an enumerated data type inside of a method.

False

You cannot assign a value to a wrapper class object.

False

You must call a method to get the value of a wrapper class object

False

All fields declared in an interface

Are final and static

StringBuffer objects are immutable.

False

In an interface all methods have

Public access

When on object is a specialized version of another object, there is a(n) ____ relationship between them.

"is a"

Protected class members are denoted in a UML diagram with the symbol

#

The following statement creates an ArrayListobject. What is the purpose of the notation? ArrayList<String> arr = new ArrayList<String>();

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

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

-1

When the this variable is used to call a constructor,

. It must be the first statement in the constructor making the call

Look at the Following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant?

1

What will be the tokens in the following statement? StringTokenizer = strToken new StringTokenizer("123-456-7890", "-",true);

123, 456 7890, and -

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

15

The parameterless constructor for a StringBuffer object gives the object enough storage space to hold ___

16 characters

What will be the value of x[8] after the following code has been 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

What will be the value of x[1] after the following code is executed? int[] x = { 22, 33, 44 }; arrayProcess(x); ... public static void arrayProcess(int[] a) { for(int k = 0; k < 3; k++) { a[k] = a[k] + 5; } }

38

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

456

Given the following two-dimensional array declaration, which statement is true? int [][] numbers = new int [6] [9];

The array numbers has 6 rows and 9 columns

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

A case experssion

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

A chain of inheritance

If the this variable is used as a constructor call,

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

If the this variable is used as a constructor call,

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

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

A ragged array is

A two-dimensional array when the rows are of different lengths

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

ABC

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

All of the above

When an "is a" relationship exists between objects, it means that the specialized object has

All the characteristics of the general object, plus additional chracteristics

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

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

When using StringBuffer insert method, you cannot insert

Another StringBuffer type

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

ClassB

Given the following statement which of the following is true? public class ClassB implements ClassA{ }

ClassB must override each method in ClassA

In memory, an array of String objects

Consists of an array of references to Stringobjects

In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the spaces or other characters is

Delimiter

All methods in an abstract class must also be declared abstract

False

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

False

If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one fore each delimiter character.

False

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

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 derived class constructor always executes before the base class constructor

False

The valueOf() method accepts a string representation as an argument and returns its equivalent integer value.

False

What does the following statement do? Double number = new Double(8.8);

It Creates a Double Object; It initializes that object to 8.8; It assigns the object's address to the number variable

What does the following statement do? Float number = new Float(8.8);

It creates a Float Object; It initializes that object to 8.8; It assigns the object's address to the number variable

what will be the tokens in the following statements? StringTokenizer strToken = newStringTokenizer("January 1, 2003", ",",true);

January, 1, 2004, space, comma

If a subclass constructor does not explicitly call as superclass constructor,

Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes

A protected member of a class may be directly accessed by

Methods of the same class; Methods of a Subclass; Methods in the Same Package

Use the following import statement when using the character wrapper class

No import statement is needed

Protected members are

Not quite private; Not quite different

A derived class can directly access

Only Public and protected members of the base class

If you do not provide an access specifier for a class member, the class member is given ___ access by default

Package

What will be returned from a method, if the following is the method header: public Rectangle getRectangle()

The address of an object in the class Rectangle

In order to do a binary search on an array,

The array must first be sorted in ascending order

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

Private Members

The difference between protected access and package is

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

If ClassA is Derived from ClassB, then

Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

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

If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?

Semicolon

To convert the double variable, d = 543.98, to a string, use the following statement,

String str = Double.toString(d);

To convert the integer vaiable, number = 56, to a string, use the following statement

String str = Integer.toString(number);

which of the following statements will print the maximum value a double variable may have?

System.out println(Double.MAX_VALUE);

Which of the following Statements will print the maximum value an integer variable may have?

System.out.println(Integer.MAX_VALUE);

The Character wrapper provides numerous methods for

Testing and converting char variables

You may use this to compare two enum data values.

The equals and compareTo methods that automatically come with the enum data type

Given the following statement, which of the following is not true? str.insert(8,32)

The insert will start at position 32

If a class contains an abstract method,

The method will have only a header, but not a body, and end with a semicolon

In a class hierachy

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

If a base class does not have a default constructor,

Then a class that is derived from it, must call one of the constructors that the base class does have

Which of the following is not true about static methods?

They are called from an instance of the class.

Few programmers use wrapper classes because

They are immutable, They are not easy to use

The only limitation that static methods have is

They cannot refer to non-static members of the class

Although it is not normally useful to create objects from the wrapper classes, programmers might use wrapper classes because

They provide static methods that are very useful

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 FeetInches object as its argument and returns a boolean value

In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the data items is

Token

Look at the following declaration. enum Tree { OAK, MAPLE, PINE } What is the fully-qualified name of the PINE enum constant?

Tree.PINE

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

True

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

True

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

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

Any items typed on the command-line, separated by 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

Every class has a toString method and equal's method inherited from the Object class

True

Every class is either directly or indirectly derived from he Object class.

True

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

True

If a class contains an abstract method

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

What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;

a = 5

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

a case expression

You can use this ArrayList class method to insert an item at a specific location in an ArrayList.

add

In the following statement, what data type must recField be: str.getChars(5, 10, recField, 0);

char[ ]

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

diddl

To convert the string, str = "285.74" to a double and store it in the variable x, use the following statement.

double x = Double.parseDouble(str);

If String str = "ABCDEFGHI," what will be returned from Character.toLowerCase(str.charAt(5))?

f

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

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

garbage collection

To use the class StringTokenizer, you must have the following import statement.

import java.util.StringTokenizer;

To convert the string, str = "285" to an integer and store it in the variable x, use the following statement

integer x = Integer.parseInt(str);

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

numAccounts = SavingsAccount.numberOfAccounts;

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

ordinal

Which of the following statements correctly specifies three interfaces:

public class ClassA implements Interface1, Interface2, Interface3

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

public class Salaried extends PayType

This ArrayList class method deletes an item from an ArrayList.

remove


Kaugnay na mga set ng pag-aaral

Chapter 18: Evaluating - FUNDAMENTALS

View Set

Section 12, Unit 3: Discrimination and Human Rights

View Set

Advanced 1 EXAM 3 sessions 10 and 11

View Set

Chapter 2 (Competitiveness, Strategy, and Productivity)

View Set

Silvana Sin Lana - Episodio 3 (Vocabulario)

View Set

BJU Heritage Studies 6 Chapter 4

View Set