Java Questions 2: A. B. C. D
Java Questions 2: A. B. C. D
1.Which four options describe the correct default values for array elements of the types indicated?
1. int -> 0
2. String -> "null"
3. Dog -> null
4. char -> '\u0000'
5. float -> 0.0f
6. boolean -> true
A. 1, 2, 3, 4
B. 1, 3, 4, 5
C. 2, 4, 5, 6
D. 3, 4, 5, 6
Answer: Option B
2.Which one of these lists contains only Java programming language keywords?
A. class, if, void, long, Int, continue
void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[ 0] + a1[1] + a1[2] + " ");
System.out.println(a2[ 0] + a2[1] + a2[2]);
}
A. 12 15
B. 15 15
C. 345375
D. 375375
Answer: Option B
A. finished
B. Exception
C. Compilation fails.
D. Arithmetic Exception
Answer: Option C
B. It can extend exactly one class and can implement multiple interfaces.
7.
void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println("start completed"); /* Line 7 */
}
B. after line 6
C. after line 7
8.What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
A. 2
B. 3
C. 4
D. 2.5
Answer: Option B
B. int b = Math.abs(5.0);
C. int c = Math.abs(5.5F);
D. int d = Math.abs(5L);
Answer: Option A
10.
interface Base
{
boolean m1 ();
byte m2(short s);
}
B. 2 and 3
C. 3 and 4
D. 1 and 5
Answer: Option C
B. 2, 4, 5
C. 1, 2, 6
D. 2, 5, 6
Answer: Option C
12.
C. public Test( )
D. public Test(void)
Answer: Option C
13.
D. "odd" will be output for odd values of x, and "even" for even values.
Answer: Option A
14.
15.Suppose that you would like to create an instance of a new Map that has an iteration order that is
the same as the iteration order of an existing instance of a Map. Which concrete implementation of
the Map interface should be used for the new instance?
A. TreeMap
B. HashMap
C. LinkedHashMap
16.Which class does not override the equals() and hashCode() methods, inheriting them directly
from class Object?
A. java.lang.String
B. java.lang.Double
C. java.lang.StringBuffer
D. java.lang.Character
Answer: Option C
B. start();
C. run();
D. resume();
Answer: Option B
B. 2 and 4
C. 1 and 2
D. 2 and 5
Answer: Option C
A. finished
B. Compiliation fails.
20.
B. Line 6
C. Line 12
D. Line 14
Answer: Option D
A. bar
B. bar done
C. foo done
D. Compilation fails
Answer: Option D
class Bar
{
Bar()
{
System.out.print("bar");
}
public void go()
{
System.out.print("hi");
}
} /* class Bar ends */
A. Compilation fails.
C. It prints "foobarhi"
D. It prints "barhi"
Answer: Option C
23.
B. throws Exception
C. catch ( Exception e )
D. throws RuntimeException
Answer: Option B
C. Any statement that can throw an Error must be enclosed in a try block.
D. Any statement that can throw an Exception must be enclosed in a try block.
Answer: Option A
An Error that might be thrown in a method must be declared as thrown by that method, or be
C.
handled within that method.
Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block
D.
will always start to execute.
Answer: Option D