File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Top-level class modifiers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Top-level class modifiers?" Watch "Top-level class modifiers?" New topic

Top-level class modifiers?

Ranch Hand

Joined: Dec 06, 2000
Posts: 35
This question appear in IBM mock exam:
I doubt if there is a correct answer:
Which of the following declarations of a top-level class Frog are legal, assuming Animal is an existing class?

a) protected class Frog extends Animal {

b) private class Frog extends Animal {

c) transient class Frog extends Animal {

d) native class Frog extends Animal

Any help will be appreciated!
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
protected and private can't be used with a top level class, as I understand. native and transient also can't be used for a class.
So, looks like we have a question for errata!!
Manish Kumar

Joined: Jun 27, 2000
Posts: 6
You are right. There isn't any correct answer, because a top-level class can only be public or 'friendly'.
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
I believe top level classes can have no modifier as well (which is known as default
class Test
public static void main(String args[])
System.out.println("Hello World!");
That should compile and print out Hello World. The class in this case is not public private or protected, but it is default.

Ryan Headley<br /><a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Top-level class modifiers?
It's not a secret anymore!