1.Which of the following statements about access modifiers public,
private, protected and default (i.e. no access modifier) is True?
A.The access modifier private is more restrictive than default.
B.The public access modifier is the least restrictive.
C.The default access modifier is more restrictive than protected.
D.The protected access modifier is more restrictive than default access modifier.
E.The private access modifier is more restrictive than protected access modifier.
2.Given:
class DCTest
{
int x=0;
public static void main(
String[] args)
{
DCTest d = new DCTest();
d.x=d.methodA();
System.out.println(d.x);
}
int methodA()
{
public int a=9;
protected int b=18;
private int c=27;
static int d=18;
native int e=18;
transient int f=18;
return a;
}
}
What is the result? Prints:
A.9
B.0
C.Compilation fails
D.methodA() should be declared static.
E.int x=0 should be declared static.
F.Only the static variable d in methodA() is accessible from main()
and can be printed.
3.Given:
package a;
public class DCTest
{
XXXXXX static int x=9;
}
package b;
import a.DCTest;
class DCQTest extends DCTest
{
public static void main(String[] args)
{
System.out.println(x);
}
}
How can you declare variable x in class DCTest so that it is not visible
outside the package a?
1.private static int x=9;
2.protected static int x=9;
3.abstract static int x=9;
4.public static int x=9;
5.static int x=9;
- Suresh Selvaraj