File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Top level class access modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Top level class access modifier" Watch "Top level class access modifier" New topic
Author

Top level class access modifier

Anselme Bender
Greenhorn

Joined: May 22, 2002
Posts: 21
On javaprepare.com I found the following question :
--
A top level class may have only the following access modifier. Select one correct answer.
A package
B friendly
C private
D protected
E public
--
They say the correct answer being E but what about the following class which compiles and runs.
-- File Simple.java ----
class Simple
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
In this case, the top level class has a package access !!!
I'm a bit puzzled and any help would be welcome
Regards
A. B.


Anselme Bender<br />SCJP2
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
You are right Anselme.
As per JLS 7.6 Top Level Type Declarations a top-level class is allowed to have a package-wide access (i.e. no modifier specified)...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
But "package" is not a legal modifier - it's a keyword meaning something else. I think that's part of what the question is intended to test. So answer E is correct. However, the question is not as clear as it could have been.


"I'm not back." - Bill Harding, Twister
Khurram Shahood(SCJP2)
Greenhorn

Joined: Jun 08, 2002
Posts: 18
HI
BASICALLY PACKAGE IS NOT A MODIFIER BUT DEFAULT MODIFIER IS USED FOR PACKAGE LEVEL.THATS Y V CAN SAY IT PACKAGE LEVEL MODIFIER.
BUT FREINDLY IS NOT A MODIFIER IN JAVA BUT DEFAULT MODIFIER IS WORKED AS A FRIENDLY MODIFIER BUT SUN MICRO SYSTEM DOESNT RECOMMEND THE USE OF KEYWORD OF FRIENDLY AS A MODIFEIR.
[ August 09, 2002: Message edited by: Khurram Shahood(SCJP2) ]

khurram shahood(Java Farmer)
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

The question has given u several choices out of which u have select the correct answers. The answer E is absolutely right and if they had given the default modifier(no keyword for this one) as another choice then it would also have been another answer.


Groovy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Top level class access modifier
 
Similar Threads
Top Level Classes
Top level class??
question regarding modifiers applicable to top level class
Top level Class can be private,protected?
Question on Access Modifiers