Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuiz - Practice Questions for SCJP2 (10/19/2003)

 
Suresh Selvaraj
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) a, b, c, e
2) c
3) a
 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. a,b,c,e
2. c
3. 1,5 (if variable has default access, it will not be available outside the package)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic