aspose file tools*
The moose likes Java in General and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "interface" Watch "interface" New topic
Author

interface

anup sachan
Greenhorn

Joined: Jan 16, 2007
Posts: 11
Which of the following are true about the class defined inside an interface

1. it is not possible in the java Laungage.
2. The class is always public.
3. The class is always static.
4. the class methods cannot call the methods declared in the interface.
5. the class methods can call only the static methods declared in the interface.

I am having doubt in this question.
I think it is not necessary to declare class as public and static in interface.but its answer is 2,3&4.
can anyone explain the answer.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961

1. it is not possible in the java Laungage.


Well this is false for a very simple reason. It is possible to declare a class inside an interface declaration.


2. The class is always public.


True, all interface members (fields, methods and classes) are public whether you declare them that way or not. If you omit the public keyword they are declared public anyway.


3. The class is always static.


Declaring a field member in a interface makes it public and static by default. It is the same thing with a class declaration. It is static by default. Something very logical, since an interface by itself cannot be instantiated it would not make sense to declare a non-static inner class.


4. the class methods cannot call the methods declared in the interface.


What would be the point, the interface must be implemented in order to invoke one of the methods. So this is ultimately true.


5. the class methods can call only the static methods declared in the interface.


It is false, you cannot you can invoke other methods declared in the same class or other objects instantiated or passed by parameters to this class.
[ January 16, 2007: Message edited by: Edwin Dalorzo ]
 
Consider Paul's rocket mass heater.
 
subject: interface