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

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

HCM21_CPL_JAVA_06    Tests & Quizzes

Tests & Quizzes

05_BTJB_Quiz3_Exception Handling & Utility Classes


Return to Assessment List

Part 1 of 1 - 62.5/ 100.0 Points

Question 1 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String s1 = "ABC";
StringBuffer s2 = new StringBuffer(s1);
System.out.print(s2.equals(s1) + "," + s1.equals(s2));
}

}
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
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 3 of 20
0.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
• Each element must be unique. 0.0/ 5.0 Points
• Contains no duplicate elements.
• Elements are not key/value pairs.
• Accessing an element can be almost as fast as performing a similar operation on an array.
Which of these classes provides the specified features?

A. LinkedList

B. TreeMap

C. TreeSet

D. HashMap

E. HashSet

F. LinkedHashMap

G. Hashtable

H. None of the above

Question 5 of 20
5.0/ 5.0 Points
class B {
public static void main (String[] args) {
byte b1 = 11;
System.out.print(new Integer(b1).equals(new Integer(b1)) + ",");
System.out.print(new Integer(b1).equals(new Short(b1)) + ",");
System.out.print(new Integer(b1).equals(new Byte(b1)));
}

}
What is the result of attempting to compile and run the program?

A. Prints: false,false,false

B. Prints: false,false,true

C. Prints: false,true,false

D. Prints: false,true,true

E. Prints: true,false,false

F. Prints: true,false,true
G. Prints: true,true,false

H. Compile-time error

I. Run-time error

J. None of the above

Question 6 of 20
• Entries are not organized as key/value pairs. 5.0/ 5.0 Points
• Duplicate entries are rejected.
Which interface of the java.util package offers the specified behavior?

A. List

B. Map

C. Set

D. None of the above

Question 7 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 8 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 9 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 10 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 11 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 12 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 13 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 14 of 20
5.0/ 5.0 Points
class M {
public static void main (String[] args) {
String s1 = "ABC";
StringBuffer s2 = new StringBuffer(s1);
System.out.print(s2.equals(s1) + "," + s1.equals(s2));
}

}
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 15 of 20
5.0/ 5.0 Points
class ColorException extends Exception {}
class WhiteException extends ColorException {}
class White {
void m1() throws ColorException {throw new WhiteException();}
void m2() throws WhiteException {}
public static void main (String[] args) {
White white = new White();
int a,b,d,f; a = b = d = f = 0;
try {white.m1(); a++;} catch (ColorException e) {b++;}
try {white.m2(); d++;} catch (WhiteException e) {f++;}
System.out.print(a+","+b+","+d+","+f);
}

}
What is the result of attempting to compile and run the program?

A. Prints: 0,1,0,0

B. Prints: 1,1,0,0

C. Prints: 0,1,1,0

D. Prints: 1,1,1,0

E. Prints: 1,1,1,1

F. Compile-time error

G. Run-time error

H. None of the above

Question 16 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 17 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 18 of 20
5.0/ 5.0 Points
class A {
public static void main(String[] args) {
Boolean b1 = new Boolean(true); // 1
Boolean b2 = new Boolean(false); // 2
Boolean b3 = new Boolean(TRUE); // 3
Boolean b4 = new Boolean(FALSE); // 4
Boolean b5 = new Boolean("TrUe"); // 5
Boolean b6 = new Boolean("fAlSe"); // 6
}

}
Compile-time errors are generated at which lines? (Multi choice)

A. 4

B. 5

C. 6

D. 1

E. 2

F. 3

Question 19 of 20
• Entries are organized as key/value pairs. 0.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 20 of 20
2.5/ 5.0 Points
class H {
public static void main (String[] args) {
int i1, i2; Integer i3, i4;
i1=new Integer(Integer.parseInt("1")).intValue(); // 1
i3=new Integer(Integer.parseInt("1")).intValue(); // 2
i2=Integer.parseInt(Integer.valueOf("1").toString()); // 3
i4=Integer.parseInt(Integer.valueOf("1").intValue()); // 4
}

}
What is the result of attempting to compile and run the program? (Multi choice)

A. Compile-time error at 3.

B. Compile-time error

C. Compile-time error at 2.

D. Compile-time error at 4.

E. Run-time error

F. Compile-time error at 1.

Gateway
Accessibility Information
The Sakai Project

Powered by Sakai
Copyright 2017 FPT-Software

You might also like