• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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
 
Hot dog! An advertiser loves us THIS much:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic