What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
A -
public
B -
abstract
C -
synchronized
D -
default access
2-
You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?
public class Switch2
{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 3; z++)
{
switch (z)
{
case x: System.out.print("0 ");
case x-1: System.out.print("1 ");
case x-2: System.out.print("2 ");
}
}
}
}
A -
0 1 2
B -
0 1 2 1 2 2
C -
2 1 0 1 0 0
D -
2 1 2 0 1 2
6-
What will be the output of the program?
public class Switch2
{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 3; z++)
{
switch (z)
{
case y: System.out.print("0 "); /* Line 11 */
case x-1: System.out.print("1 "); /* Line 12 */
case x: System.out.print("2 "); /* Line 13 */
}
}
}
}
A -
0 1 2
B -
0 1 2 1 2 2
C -
Compilation fails at line 11.
D -
Compilation fails at line 12.
7-
What will be the output of the program?
public class Switch2
{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 4; z++)
{
switch (z)
{
case x: System.out.print("0 ");
default: System.out.print("def ");
case x-1: System.out.print("1 ");
break;
case x-2: System.out.print("2 ");
}
}
}
}
A -
0 def 1
B -
2 1 0 def 1 def 1
C -
2 1 0 def def
D -
2 1 0 def 1
8-
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
A -
java.util.HashSet
B -
java.util.LinkedHashSet
C -
java.util.List
D -
java.util.ArrayList
9-
What will be the output of the program?
public class Test
{
public static void main (String args[])
{
String str = NULL;
System.out.println(str);
}
}
A -
NULL
B -
Compile Error
C -
Code runs but no output
D -
Runtime Exception
10-
Which of the following will not directly cause a thread to stop?