• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) a, b, c, e
2) c
3) a
 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Hey cool! They got a blimp! But I have a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic