0% found this document useful (0 votes)
50 views11 pages

05 - BTJB - Quiz3 - Exception Handling & Utility Classes: Tests & Quizzes

The document contains a quiz with 20 multiple choice questions about Java exception handling and utility classes. The questions cover topics like the Throwable class hierarchy, HashMap features, StringBuffer behavior, and List/Map interface implementations. Sample programs are provided with each question to demonstrate expected output.

Uploaded by

John Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views11 pages

05 - BTJB - Quiz3 - Exception Handling & Utility Classes: Tests & Quizzes

The document contains a quiz with 20 multiple choice questions about Java exception handling and utility classes. The questions cover topics like the Throwable class hierarchy, HashMap features, StringBuffer behavior, and List/Map interface implementations. Sample programs are provided with each question to demonstrate expected output.

Uploaded by

John Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

HCM21_CPL_JAVA_06    Tests & Quizzes

Tests & Quizzes

05_BTJB_Quiz3_Exception Handling & Utility Classes


Return to Assessment List

Part 1 of 1 - 72.5/ 100.0 Points

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

G. None of the above

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

G. None of the above

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

J. None of the above

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

J. None of the above

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

G. None of the above

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

G. None of the above

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

G. None of the above

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

I. None of the above

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

D. None of the above

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

G. None of the above

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

E. None of the above

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

D. None of the above

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

E. None of the above

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

G. None of the above

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

C. None of the above

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

G. None of the above

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

G. None of the above

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

G. None of the above

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.

B. class A extends Object.

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

You might also like