REVIEW

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

15) What will be the value of str after the following statements are executed? StringBuilder str = new StringBuilder("We have lived in Chicago, " + "Trenton, and Atlanta."); str.replace(17, 24, "Tampa"); A) We have lived in Tampa, Trenton, and Atlanta. B) We have lived in Chicago, Tampa, and Atlanta. C) We have lived in Tampa Trenton, and Tampa. D) We have lived in Tampalanta.

A

16) Sometimes a string will contain a series of words or other items of data separated by spaces or other characters. In programming terms, items such as these are known as what? A) Tokens B) Delimiters C) Key characters D) Lists

A

17) If the this variable is used to call a constructor: A) a compiler error will result, if it is not the first statement of the constructor B) a compiler error will result, if it is the first statement of the constructor C) nothing will happen D) the this variable cannot be used as a constructor call

A

4) In an inheritance relationship: A) The superclass constructor always executes before the subclass constructor B) The subclass constructor always executes before the superclass constructor C) The constructor with the lowest overhead always executes first regardless of inheritance D) The unified constructor always executes first regardless of inheritance

A

5) Java automatically stores this value in all uninitialized static member variables: A) 0 B) -1 C) null D) false

A

20) If ClassC extends ClassB, which extends ClassA, this would be an example of: A) multiple inheritance B) a chain of inheritance C) a family tree D) packaging

B

1) A static field is created by placing: A) the key word static after the field name B) the key word static after the access specifier and before the field's data type C) the key word static after the access specifier and field's data type D) it in a static field block

B

10) When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings, use this method to delete them. A) replace B) trim C) valueOf D) substring

B

14) Why does the following code cause a compiler error? try { number = Integer.parseInt(str); } catch (IllegalArgumentException e) { System.out.println("Bad number format."); } catch (NumberFormatException e) { System.out.println(str + " is not a number."); } A) Because you can have only one catch clause in a try statement B) Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException C) Because the Integer.parseInt method does not throw a NumberFormatException D) Because the Integer.parseInt method does not throw an IllegalArgumentException

B

15) A deep copy of an object: A) is an assignment of that object to another object B) is an operation that copies an aggregate object, and all the objects it references C) is a bogus term, it has no meaning D) is always a private method

B

16) The IllegalArgumentException class extends the RuntimeException class, and is therefore: A) a checked exception class B) an unchecked exception class C) never used directly D) none of the above

B

2) The Character wrapper class provides numerous methods for: A) testing String objects B) testing and converting char variables C) converting String variables D) adding two char variables

B

20) 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? A) getNumberOfAccounts(); B) SavingsAccount.getNumberOfAccounts(); C) getNumberOfAccounts(account20); D) None of the above, you cannot call a static method.

B

27) Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant? A) 0 B) 1 C) 2 D) 3 E) Tree.MAPLE

B

33) The JVM periodically performs this process to remove unreferenced objects from memory. A) memory sweeping B) garbage collection C) memory shuffling D) system restore

B

7) When a reference variable is passed as an argument to a method: A) a copy of the variable's value is passed into the method's parameter B) the method has access to the object that the variable references C) the method becomes a static method D) the program will terminate

B

9) When a method's return type is a class, what is actually returned to the calling program? A) An object of that class B) A reference to an object of that class C) Only the values in the object that the method accessed D) Nothing, the return type is strictly for documentation in this situation.

B

34) The no-arg constructor for a StringBuilder object gives the object enough storage space to hold this many characters. A) 0 characters B) 8 characters C) 16 characters D) 32 characters

C

1) What is term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables? A) Intrinsic class B) Enclosed object C) Wrapper class D) Transitional object

C

11) If your program needs to make a lot of changes to one or more string, you might consider using objects of this class: A) Character B) String C) StringBuilder D) All of the above

C

24) If you attempt to perform an operation with a null reference variable: A) the resulting operation will always be zero B) the results will be unpredictable C) the program will terminate D) Java will create an object to reference the variable

C

4) 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++; }

C

5) In a try/catch construct, after the catch statement is executed: A) the program returns to the statement following the statement in which the exception occurred B) the program terminates C) the program resumes at the statement that immediately follows the try/catch construct D) the program resumes at the first statement of the try statement

C

6) If you have defined a class named 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? A) numAccounts = account20.numAccounts; B) numAccounts = numberOfAccounts; C) numAccounts = SavingsAccount.numberOfAccounts; D) None of the above, you cannot reference a static data member.

C

7) What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } } A) Nothing is wrong with the code. B) The method super is not defined. C) The call to the method super must be the first statement in the constructor. D) No values may be passed to super.

C

9) This character is one that appears at the end, or right side, of a string, after the non-space characters: A) Leading whitespace B) Carriage return C) Trailing whitespace D) Line feed

C

16) A protected member of a class may be directly accessed by: A) methods of the same class B) methods of a subclass C) methods in the same package D) All of the above

D

23) If a class contains an abstract method: A) you cannot create an instance of the class B) the method will have only a header, but not a body, and end with a semicolon C) the method must be overridden in subclasses D) All of the above

D

30) A subclass can directly access: A) all members of the superclass B) only public and private members of the superclass C) only protected and private members of the superclass D) only public and protected members of the superclass

D

31) 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); A) 15 B) 16 C) 0 D) -1

D

4) The only limitation that static methods have is: A) they can refer to only non-static members of the class B) they can only be called from static members of the class C) they must be declared as public methods D) they cannot refer to non-static members of the class

D

8) In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0); A) String B) int C) char D) char[]

D


संबंधित स्टडी सेट्स

Long-Polling vs WebSockets vs Server-Sent Events

View Set

Chapter 3: Inflammation, the Inflammatory Response, and Fever http://thepoint.lww.com/Book/Show/Level 3

View Set

History of Rock and Roll Test #2

View Set

Exam 3 Renal combined Suprapubic Pain and Hematuria

View Set