• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Question on Interface

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 coderanch.
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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic