Question 4 Marks: --/1 To convert the double variable, d = 543.98, to a string,
ID: 3535951 • Letter: Q
Question
Question
4
Marks: --/1
To convert the double variable, d = 543.98, to a string, use the following statement.
Choose one answer.
a. String str = Double.toString(d);
b. String str = double(d);
c. String str = d.Double.toString(str);
d. String str = double.toString(d);
Question
5
Marks: --/1
Look at the following code and determine what the call to super will do.
public class ClassB extends ClassA
{
public ClassB()
{
super(10);
}
}
Choose one answer.
a. It will call the constructor of ClassA that receives an integer as an argument.
b. This cannot be determined form the code.
c. It will call the method super and pass the value 40 to it as an argument.
d. The method super will have to be defined before we can say what will happen.
Question
6
Marks: --/1
In a linked list, the predecessor of a node X
Choose one answer.
a. is the node that comes after X
b. is the node that is just before X
c. is the first node in the list
d. is undefined if X is the first node, otherwise it is the node whose index is one less than the index of X
Question
7
Marks: --/1
All exceptions are instances of classes that extend this class.
Choose one answer.
a. Throwable
b. Exception
c. RunTimeException
d. Error
Question
8
Marks: --/1
If ClassA is derived from ClassB, then
Choose one answer.
a. public and private members of ClassB are public and private, respectively, in ClassA
b. private members in ClassB are changed to protected members in ClassA
c. neither public or private members in ClassB can be directly accessed in ClassA
d. public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
Question
9
Marks: --/1
Given the following code which of the following is true?
public class ClassB implements ClassA{}
Choose one answer.
a. ClassB is derived from ClassA
b. ClassB must override each method in ClassA
c. ClassA is derived from ClassB
d. ClassA must override each method in ClassB
Question
10
Marks: --/1
The catch clause
Choose one answer.
a. starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable
b. contains code to gracefully handle the exception type listed in the parameter list
c. All of the above
d. follows the try clause
Question
11
Marks: --/1
What does the following statement do?
Float number = new Float(8.8);
Choose one answer.
a. It assigns the object's address to the number variable.
b. It creates a Float object.
c. All of the above
d. It initializes that object to 8.8.
Question
12
Marks: --/1
A doubly linked list makes it easy to
Choose one answer.
a. skip two nodes at a time when moving forward through the list
b. to create a second copy of the linked list
c. skip two nodes at a time when moving backward through the list
d. move from any node to its successor, and from any node to its predecessor
Question
13
Marks: --/1
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);
Choose one answer.
a. Iddle
b. diddle
c. , didd
d. diddl
Question
14
Marks: --/1
To allocate storage for its elements, an array-based list such as ArrayList uses
Choose one answer.
a. fixed size allocation
b. linked allocation
c. contiguous allocation
d. capacity allocation
Question
15
Marks: --/1
All of the exceptions that you will handle are instances of classes that extend this class.
Choose one answer.
a. RunTimeException
b. IOException
c. Exception
d. Error
Question
16
Marks: --/1
What will be the result of the following statements?
FileInputStream fstream =
new FileInputStream("DataIn.dat");
DataInputStream inFile =
new DataInputStream(fstream);
Choose one answer.
a. The inFile variable will reference an object that is able to read text data from the Input.dat file.
b. The inFile variable will reference an object that is able to read random access data from the Input.dat file.
c. The inFile variable will reference an object that is able to read binary data from the Input.dat file.
d. The inFile variable will reference an object that is able to write binary data to the Input.dat file.
Question
17
Marks: --/1
If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of
Choose one answer.
a. packaging
b. a chain of inheritance
c. a family tree
d. multiple inheritance
Question
18
Marks: --/1
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String tokens = str.split("[$&#]");
Choose one answer.
a. None of these
b. "red", "green", "blue"and "orange"
c. "[", "$", "&", "#", and "]"
d. "$", "&", and "#"
Question
19
Marks: --/1
If you want to append data to the existing binary file, BinaryFile.dat, use the following statements to open the file.
Choose one answer.
a. FileOutputStream fstream =
new FileOutputStream("BinaryFile.dat", true);
DataOutputStream binaryOutputFile =
new DataOutputStream(fstream);
b. FileOutputStream fstream =
new FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
new DataOutputStream(fstream, true);
c.
FileOutputStream fstream =
new FileOutputStream("BinaryFile.dat", false);
DataOutputStream binaryOutputFile =
new DataOutputStream(fstream);
d. FileOutputStream fstream =
new FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
new DataOutputStream(fstream);
Question
20
Marks: --/1
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,
productCodes[1], 2, 3);
Choose one answer.
a. 56H
b. false
c. true
d. 56h
Question
21
Marks: --/1
If a random access file contains a stream of characters, which of the following would you use to set the pointer on the fifth character?
Choose one answer.
a. file.seek(8);
b. file.seek(5);
c. file.seek(9);
d. file.seek(4);
Question
22
Marks: --/1
A linked list class uses a Node class with successor reference next and field element to store values. A recursive method to print all list elements can be written as
Choose one answer.
a. static void printList(Node list)
{
if (list != null)
{
System.out.println(list.element);
printList(list.next);
}
}
b. static void printList(Node list)
{
System.out.println(list.element):
printList(list.next);
}
c. static void printList(Node list)
{
while (list.next != null)
{
printList(list.next);
System.out.println(list.element)
list ++;
}
}
d. static void printList(Node list)
{
while (list!= null)
{
System.out.println(list.element)
printList(list.next);
list = list.next;
}
}
Question
23
Marks: --/1
When you write a method that throws a checked exception, you must
Choose one answer.
a. ensure that the error will occur at least once each time the program is executed
b. override the default error method
c. have a throws clause in the method header
d. use each class only once in a method
Question
24
Marks: --/1
Look at the following code. What is missing from ClassA?
Line 1 public interface MyInterface
Line 2 {
Line 3 int FIELDA = 55;
Line 4 public int methodA(double);
Line 5 }
Line 6 public class ClassA implements MyInterface
Line 7 {
Line 8 FIELDA = 60;
Line 9 public int methodB(double) { }
Line 10 }
Choose one answer.
a. It does not override methodA.
b. It is a complete class.
c. It does not overload methodA.
d. It does not have a constructor.
Question
25
Marks: --/1
Look at the following code.
Integer myNumber;
myNumber = 5;
Which of the following is true about the second statement?
Choose one answer.
a. It results in an error because you cannot assign a primitive type to a wrapper class object.
b. The statement performs autowrapping.
c. The statement performs autoboxing.
d. The statement performs unboxing.
Question
26
Marks: --/1
To serialize an object and write it to the file, use this method of the ObjectOutputStream class.
Choose one answer.
a. SerializeAndWrite
b. Serialize
c. SerializeObject
d. WriteObject
Question
27
Marks: --/1
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.");
}
Choose one answer.
a. Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException.
b. Because you can have only one catch clause in a try statement.
c. Because the Integer.parseInt method does not throw a NumberFormatException.
d. Because the Integer.parseInt method does not throw an IllegalArgumentException.
Question
28
Marks: --/1
In the following statement, which is the interface?
public class ClassA extends ClassB implements ClassC
Choose one answer.
a. Cannot tell
b. ClassA
c. ClassC
d. ClassB
Question
29
Marks: --/1
Like ________, a recursive method must have some way to control the number of times it repeats.
Choose one answer.
a. a loop
b. a rumor
c. a GUI method
d. any method
Question
30
Marks: --/1
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use
Choose one answer.
a. the Scanner class methods
b. the System.In and System.Out methods
c. methods that use UTF-8 encoding
d. the FileReader and Writer class methods
Question
31
Marks: --/1
Look at the following code.
Line 1 public class ClassA
Line 2 {
Line 3 public ClassA() {}
Line 4 public void method1(int a){}
Line 5 }
Line 6 public class ClassB extends ClassA
Line 7 {
Line 8 public ClassB(){}
Line 9 public void method1(){}
Line 10 }
Line 11 public class ClassC extends ClassB
Line 12 {
Line 13 public ClassC(){}
Line 14 public void method1(){}
Line 15 }
Which method will be executed when the following statements are executed?
ClassC item1 = new ClassA();
item1.method1();
Choose one answer.
a. Line 14
b. Line 9
c. Line 4
d. This is an error and will cause the program to crash.
Question
32
Marks: --/1
What is wrong with the following code?
public class ClassB extends ClassA
{
public ClassB()
{
int init = 10;
super(40);
}
}
Choose one answer.
a. No values may be passed to super.
b. The call to the method super must be the first statement in the constructor.
c. Nothing is wrong with the code.
d. The method super is not defined.
Question
33
Marks: --/1
If a class contains an abstract method,
Choose one answer.
a. you cannot create an instance of the class
b. All of the above
c. the method must be overridden in subclasses
d. the method will have only a header, but not a body, and end with a semicolon
Question
34
Marks: --/1
Protected members are
Choose one answer.
a. not quite public
b. not quite private
c. Both A and B
d. Neither A nor B
Question
35
Marks: --/1
Look at the following code:
FileInputStream fstream =
new FileInputStream("MyInfo.dat");
DataInputStream inputFile =
new DataInputStream(fstream);
This code can also be written as:
Choose one answer.
a. DataInputStream inputFile =
new DataInputStream(new FileInputStream("MyInfo.dat"));
b. DataInputStream inputFile =
new DataInputStream("InputFile.txt");
c. FileInputStream inputFile =
new FileInputStream(new DataInputStream("MyInfo.dat"));
d. FileInputStream fstream =
new DataInputStream("InputFile.txt");
Question
36
Marks: --/1
A subclass class can directly access
Choose one answer.
a. all members of the superclass class
b. only protected and private members of the superclass class
c. only public and private members of the superclass class
d. only public and protected members of the superclass class
Question
37
Marks: --/1
In a catch statement, what does the following code do?
System.out.println(e.getMessage());
Choose one answer.
a. It overrides the toString method.
b. It prints the code that caused the exception.
c. It prints the error message for an exception.
d. It prints the stack trace.
Question
38
Marks: --/1
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");
Choose one answer.
a. 15
b. 17
c. 16
d. 18
Question
39
Marks: --/1
If a superclass does not have a default constructor,
Choose one answer.
a. then a class that inherits from it, must initialize the superclass values
b. then a class that inherits from it, must call one of the constructors that the superclass does have
c. then a class that inherits from it, must contain the default constructor for the superclass
d. then a class that inherits from it, does not inherit the data member fields from the superclass
Question
40
Marks: --/1
Every class is either directly or indirectly derived from the Object class.
Answer:
True
False
Question
41
Marks: --/1
Every class has a toString method and an equals method inherited from the Object class.
Answer:
True
False
Question
42
Marks: --/1
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
Answer:
True
False
Question
43
Marks: --/1
When testing for character values, the switch statement does not test for the case of the character.
Answer:
True
False
Question
44
Marks: --/1
In an inheritance relationship, the derived class constructor always executes before the base class constructor.
Answer:
True
False
Question
45
Marks: --/1
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.
Answer:
True
False
Question
46
Marks: --/1
When an exception is thrown by a method that is executing under several layers of method calls, a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order go execute that method.
Answer:
True
False
Question
47
Marks: --/1
All methods in an abstract class must also be declared abstract.
Answer:
True
False
Question
48
Marks: --/1
StringBuilder objects are immutable.
Answer:
True
False
Question
49
Marks: --/1
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.
Answer:
True
False
Question
50
Marks: --/1
If class, SerializedClass, contains objects of other classes as fields, those classes must also implement the Serializable interface, in order to be serialized.
Answer:
True
False
Explanation / Answer
a. String str = Double.toString(d) b. This cannot be determined form the code. a. is the node that comes after X c. RunTimeException d. public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA b. ClassB must override each method in ClassA a. starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable a. It assigns the object's address to the number variable c. skip two nodes at a time when moving backward through the list a. Iddle a. fixed size allocation c. Exception b. The inFile variable will reference an object that is able to read random access data from the Input.dat file. c. a family tree b. "red", "green", "blue"and "orange" a. FileOutputStream fstream = new FileOutputStream("BinaryFile.dat", true); DataOutputStream binaryOutputFile = new DataOutputStream(fstream); a. 56H c. file.seek(9); b. static void printList(Node list) { System.out.println(list.element): printList(list.next); } d. use each class only once in a method c. It does not overload methodA. c. The statement performs autoboxing. b. Serialize a. Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException. b. ClassA c. a GUI method a. the Scanner class methods b. Line 9 c. Nothing is wrong with the code c. the method must be overridden in subclasses a. not quite public a. DataInputStream inputFile = new DataInputStream(new FileInputStream("MyInfo.dat")); c. only public and private members of the superclass class] a. It overrides the toString method. c. 16 b. then a class that inherits from it, must call one of the constructors that the superclass does have True True False True False True True False True True False
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.