• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Q from DAN's Nested class exam

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Question 8
Which of the follow are true statements.
a. A nested class is any class that is declared within the body of another class or interface.
b. A nested class can not be declared within the body of an interface declaration.
c. A top level class is a class this is not a nested class.
d. An inner class is a nested class that is not static.
e. A nested class can not be declared static.
f. A named class is any class that is not anonymous.
g. None of the above


Answer a is also correct. How can an interface include nested class. I thought interface is only a protocal that defines what will be in implementing classes, without any implementation in itself. If nested class in interface, it has to have implementation...
Thanks
Barkat
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Barkat Mardhani:

How can an interface include nested class. I thought interface is only a protocal that defines what will be in implementing classes, without any implementation in itself. If nested class in interface, it has to have implementation...


If you take a look at the JLS, §9.5 Member Type Declarations you'll see:


Interfaces may contain member type declarations (�8.5). A member type declaration in an interface is implicitly static and public.


It's true that any methods defined within an Interface are implicitly abstract and therefore have no definition, but an Interface is also capable of containing a nested class. That class, on the other hand may have fully defined methods within it.
I hope that helps,
Corey
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic