aspose file tools*
The moose likes Java in General and the fly likes Question on 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 "Question on Interface" Watch "Question on Interface" New topic
Author

Question on Interface

Anand Sidharth
Ranch Hand

Joined: Dec 17, 2003
Posts: 44
Can any one tell the correct answer for the following question and explain why?

Q: Which of the following are true about the class defined inside an interface
ANS:
1).it is not possible in the java Language.
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.

The answer given was 2, 3 and 4


Thanks, Anand
Scotty Sinclair
Greenhorn

Joined: Jun 26, 2003
Posts: 17
1) It is possible,
2) It is allways public because an interface by default makes all members public even when a modifier isn't specified.
3) This class is allways static but I'm not sure of the reason why, it could be that interfaces don't have any "this" pointer thus making it impossible for an inner class to reference i
4) It can call the methods as long as the inner class method has a reference to an object which implements the outer interface.
5) False, it can call any method in the interface, a static inner class means that an instance of the inner class has by default no relationship to an instanceof the outer class. Infact a non-static inner class CANNOT be created unless the outer class is created first.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
4- true, there are no methods in an interface, only prototypes of methods.
Of course, if the inner class implemented the interface, then it would have to define a method body for all method prototypes of the interface, which could be called by another method of the inner class. But then, it would be a method of the inner class being called, not a method of the interface
5- false, interfaces may not have static method prototypes, hence, there's nothing to call.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Interface