File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Top-level class modifiers?

 
Jason
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question appear in IBM mock exam:
I doubt if there is a correct answer:
8)
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Jason
You are right. There isn't any correct answer, because a top-level class can only be public or 'friendly'.
Manish
 
ryan headley
Ranch Hand
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic