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

Nested Class

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

Which of the follw are true statements.
1) A nested class is any class that is declared within the body of another class or interface.
2) A nested class can not be declared within the body of an interface declaration.
3) A top level class is a class which is not a nested class.
4) An inner class is a nested class that is not static.
5) A nested class can not be declared static.
6) A named class is any class that is not anonymous.
7) None of the above.


According to me 2,3,6 are correct. Am i right or wrong? Can anybody please justify.
Thanks.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) A nested class is any class that is declared within the body of another class or interface.
2) A nested class can not be declared within the body of an interface declaration.
3) A top level class is a class which is not a nested class.
4) An inner class is a nested class that is not static.
5) A nested class can not be declared static.
6) A named class is any class that is not anonymous.
7) None of the above.

Options 1,3,4,6 are correct
1. A class can be declared inside an interface and will execute successfully.
4. Nested classes are classified as -
a. Static member class, and
b. Inner class (that includes - Non-static member class, Local class and anonymous class).

I hope this clarifies your doubts.
 
Pankaj Patel
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I am hanging between nested class and inner class.

Telling in detail :
-> A inner class is a class defined in a class of interface.
-> A class can be called as nested class if it is static inner class.
So both inner class and nested class is different word. Am i right?
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pankaj Patel:
Yes. I am hanging between nested class and inner class.

Telling in detail :
-> A inner class is a class defined in a class of interface.
-> A class can be called as nested class if it is static inner class.
So both inner class and nested class is different word. Am i right?



i just finished reviewing K&B chapter 8,
from my understanding inner class simply means a non-static class implemented in a class;
nested class , has to be static, not really a "class", but just another static member of a class; it doesnt have the relationship with the outer class, it cant use other members of the class.

i could be wrong, open to discuss
 
ice is for people that are not already cool. Chill with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic