Java Questions 1: A. B. C. D
Java Questions 1: A. B. C. D
B. native
C. subclasses
D. reference
E. array
Answer: Option B
B. string
C. Float
D. unsigned
Answer: Option A
void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}
A. slip stream
B. slipstream stream
A. BD
B. BCD
C. BDE
D. BCDE
Answer: Option C
6.Which is true about a method-local inner class?
A. It must be marked final.
8.
class Bar { }
class Test
{
Bar doBar()
{
Bar b = new Bar(); /* Line 6 */
return b; /* Line 7 */
}
public static void main (String args[])
{
Test t = new Test(); /* Line 11 */
Bar newBar = t.doBar(); /* Line 12 */
System.out.println( "newBar");
newBar = new Bar(); /* Line 14 */
System.out.println( "finishing"); /* Line 15 */
}
}
At what point is the Bar object, created on line 6, eligible for garbage collection?
A. after line 12
B. after line 14
B. 2, 3 and 4
C. 1, 2 and 3
D. 3 and 4
Answer: Option A
10.
Select how you would start the program to cause it to print: Arg is 2
A. java Myfile 222
B. java Myfile 1 2 2 3 4
C. java Myfile 1 3 2 2
D. java Myfile 0 1 2 3
Answer: Option C
C. Compilation fail
D. Cannot say.
Answer: Option B
B. 2 and 3
C. 3 and 4
D. 4 and 5
Answer: Option D
13.
interface Base
{
boolean m1 ();
byte m2(short s);
}
B. 2 and 3
C. 3 and 4
D. 1 and 5
Answer: Option C
14.
B. Test(void)
C. public Test( )
D. public Test(void)
Answer: Option C
15.
D. "odd" will be output for odd values of x, and "even" for even values.
Answer: Option A
16.
B. baz = null
C. baz = blue
D. Runtime Exception
Answer: Option D
B. If a class has synchronized code, multiple threads can still access the nonsynchronized code.
Variables can be protected from concurrent access problems by marking them with
C.
the synchronized keyword.
B. 2 and 3
C. 1 and 4
D. 3 and 4
Answer: Option C
20.What will be the output of the program (when you run with the -ea option) ?
public class Test
{
public static void main(String[] args)
{
int x = 0;
assert (x > 0) : "assertion failed"; /* Line 6 */
System.out.println( "finished");
}
}
A. finished
B. Compilation fails.
21.
When is the Float object, created in line 3, eligible for garbage collection?
A. just after line 5
22.
class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
doComplexStuff();
}
}
after line 11 runs, how many objects are eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
Answer: Option C
23.
B. 2 and 3
C. 3 and 4
B. 2 and 4
C. 3 and 4
D. 1 and 3
Answer: Option B
A. 012
B. 012122
C. 210100
D. 212012
Answer: Option D
B. 1
C. 101
D. 111
Answer: Option C