aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQuiz - Practice Questions for SCJP2 (10/19/2003) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQuiz - Practice Questions for SCJP2 (10/19/2003)" Watch "JQuiz - Practice Questions for SCJP2 (10/19/2003)" New topic
Author

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

Suresh Selvaraj
Ranch Hand

Joined: Nov 14, 2000
Posts: 104
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


Suresh Selvaraj, (author of JQuiz)<br />SCJP2<br /><a href="http://www.decontconsulting.com" target="_blank" rel="nofollow">www.decontconsulting.com</a>
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
1) a, b, c, e
2) c
3) a


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
1. a,b,c,e
2. c
3. 1,5 (if variable has default access, it will not be available outside the package)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JQuiz - Practice Questions for SCJP2 (10/19/2003)