Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Top-level class modifiers?  RSS feed

 
Jason
Ranch Hand
Posts: 35
  • 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
  • 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
  • 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
  • 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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!