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
Joined: Jun 13, 2000
Posts: 66
posted
0
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
Joined: Jun 27, 2000
Posts: 6
posted
0
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
Joined: Jun 28, 2000
Posts: 156
posted
0
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="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>