05 - BTJB - Quiz3 - Exception Handling & Utility Classes: Tests & Quizzes
05 - BTJB - Quiz3 - Exception Handling & Utility Classes: Tests & Quizzes
Question 1 of 20
5.0/ 5.0 Points
class A {
public static void main (String[] args) {
Error error = new Error();
Exception exception = new Exception();
System.out.print((exception instanceof Throwable) + ",");
System.out.print(error instanceof Throwable);
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 2 of 20
• Stores key/value pairs. 5.0/ 5.0 Points
• Allows null elements, keys, and values.
• Duplicate entries replace old entries.
• Entries are not sorted.
Which of these classes provides the specified features?
A. LinkedList
B. TreeMap
C. TreeSet
D. HashMap
E. HashSet
F. Hashtable
Question 3 of 20
5.0/ 5.0 Points
class M {
static void m1(StringBuffer s1) {
s1 = s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1.append("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}
}
What is the result of attempting to compile and run the program?
A. Prints: AAA
B. Prints: ABAA
C. Prints: ABACA
D. Prints: ABABAB
E. Prints: ABABCAB
F. Prints: ABABCABC
G. Prints: ABCABCABC
H. Compile-time error
I. Run-time error
Question 4 of 20
class M { 5.0/ 5.0 Points
static void m1(StringBuffer s1) {
s1 = s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1.append("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}
}
What is the result of attempting to compile and run the program?
A. Prints: AAA
B. Prints: ABAA
C. Prints: ABACA
D. Prints: ABABAB
E. Prints: ABABCAB
F. Prints: ABABCABC
G. Prints: ABCABCABC
H. Compile-time error
I. Run-time error
Question 5 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String s1 = new String("ABC"), s2 = new String("ABC");
StringBuffer sb1 = new StringBuffer(s1);
StringBuffer sb2 = new StringBuffer(s2);
System.out.print(s1.equals(s2) + "," + sb1.equals(sb2));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 6 of 20
5.0/ 5.0 Points
class B {
public static void main (String args[]) {
Byte b1 = new Byte(1); // 1
Byte b2 = new Byte('2'); // 2
Byte b3 = new Byte("3"); // 3
byte i1 = b1.byteValue()+b2.byteValue()+b3.byteValue(); // 4
System.out.print(i1);
}
}
What is the result of attempting to compile and run the program? (Multi choice)
A. Compile-time error at 2
B. Run-time error
C. Compile-time error at 3
D. Compile-time error at 4
E. Prints: 6
F. Compile-time error at 1
Question 7 of 20
• Stores key/value pairs. 0.0/ 5.0 Points
• Duplicate entries replace old entries.
• Entries are sorted using a Comparator or the Comparable interface.
Which of these classes provides the specified features?
A. LinkedList
B. TreeMap
C. TreeSet
D. HashMap
E. HashSet
F. Hashtable
Question 8 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
StringBuffer sb1 = new StringBuffer("ABC");
StringBuffer sb2 = new StringBuffer("ABC");
System.out.print((sb1==sb2)+","+sb1.equals(sb2));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 9 of 20
5.0/ 5.0 Points
class M {
static void m1(StringBuffer s1) {
s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1 = new StringBuffer("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}
}
What is the result of attempting to compile and run the program?
A. Prints: AAA
B. Prints: ABCA
C. Prints: ABCAB
D. Prints: ABCABC
E. Prints: ABCAC
F. Prints: ABABCABC
G. Compile-time error
H. Run-time error
Question 10 of 20
• Entries are organized as key/value pairs. 5.0/ 5.0 Points
• Duplicate entries replace old entries.
Which interface of the java.util package offers the specified behavior?
A. List
B. Map
C. Set
Question 11 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] s) {
String s1 = new String("ABCDEFG"), s2 = new String("EFGHIJ");
String s3 = s1.substring(4,7), s4 = s2.substring(0,3);
System.out.println((s3 == s4) + "," + (s3 + s4).equals(s4 + s3));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 12 of 20
0.0/ 5.0 Points
class A {
public static void main (String args[]) {
Integer i1 = new Integer(1);
Integer i2 = new Integer(i1);
System.out.print(i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false
B. Prints: true
C. Compile-time error
D. Run-time error
Question 13 of 20
Which implementation of the List interface provides for the fastest insertion of a new element 0.0/ 5.0 Points
into the middle of the list?
A. Vector
B. ArrayList
C. LinkedList
Question 14 of 20
0.0/ 5.0 Points
class A {
public static void main (String args[]) {
Double d1 = new Double(1.0);
Double d2 = new Double(d1);
System.out.print(d1.equals(d2));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false
B. Prints: true
C. Compile-time error
D. Run-time error
Question 15 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] args) {
String s1 = "A", s2 = "a", s3 = "b";
s1.toLowerCase(); s3.replace('b','a');
System.out.print((s1.equals(s2)) + "," + (s2.equals(s3)));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 16 of 20
5.0/ 5.0 Points
Which implementation of the List interface produces the slowest access to an element in the middle of the list
by means of an index?
A. ArrayList
B. LinkedList
D. Vector
Question 17 of 20
5.0/ 5.0 Points
class G {
public static void main (String[] args) {
Integer i1 = new Integer("1"), i2 = new Integer("1");
StringBuffer sb1 = new StringBuffer("1");
StringBuffer sb2 = new StringBuffer("1");
System.out.print(sb1.equals(sb2)+","+i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 18 of 20
0.0/ 5.0 Points
class B {
public static void main (String args[]) {
Long i1 = new Long(1);
Long i2 = new Long(i1);
System.out.print((i1==i2) + "," + i1.equals(i2));
}
}
What is the result of attempting to compile and run the program?
A. Prints: false,false
B. Prints: false,true
C. Prints: true,false
D. Prints: true,true
E. Compile-time error
F. Run-time error
Question 19 of 20
5.0/ 5.0 Points
class M {
public static void main(String[] s) {
String s1 = "1", s2 = "2", s3 = s1 + s2;
s1 += s2; s3 += s1;
System.out.println(s3);
}
}
What is the result of attempting to compile and run the program?
A. Prints: 3
B. Prints: 6
C. Prints: 33
D. Prints: 1212
E. Compile-time error
F. Run-time error
Question 20 of 20
class A {A() throws Exception {}} // 1 2.5/ 5.0 Points
class B extends A {B() throws Exception {}} // 2
class C extends A {C() {}} // 3
Which of the following statements are true? (Multi choice)
A. Compile-time error at 3.
C. Compile-time error at 1.
D. Compile-time error at 2.
Gateway
Accessibility Information
The Sakai Project
Powered by Sakai
Copyright 2017 FPT-Software