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

Inner Classes

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html>
<pre>

Hi there..First of all,I would like to thank u all at Java ranch.U jave made learning a little bit easier.
I an writing my exam on Oct 6th.During my preparations,I made up a few pts. about inner classes.
I think they may be useful.
Pls do correct me if I am wrong..and pls remember me in ur prayers.
Adios mes amigos!!!

INNER CLASSES(PTS TO BE NOTED)
1) Package level classes
a) Accessibility modifiers: public or default(ie: if I give protected or private it gives an error)
b) Defines both static/non-static members.

2) Top level nested class(static)
a) Accessibility modifiers : can be any(ie even private is allowed).
b) Defines both static & non-static members.
c) No need for creating instance of enclosing class.
d) Can access only static members of enclosing class.
3) Non-static Inner class
a) Accessibility modifiers : Can be any(ie: even private is allowed).
b) Defines only non-static members(ie: if I declare a static variable in the inner class ,it shows an error).
c) We have to create an instance of the enclosing class.
Imp:
Suppose I have a top level class Strat ,and an inner class Dew:
I can only say new Strat().new Dew();
Suppose instance of Strat is s1 and instance of Dew is dew1
I can't say s1.dew1
d)Can access all members of enclosing class.

4) Local class(static) : block with static context (class within a method)
a) Accessibity modifiers : Can be only default(ie:no private/public/protected).
b) Defines only non-static members. (ie: if I declare a static variable in the inner class ,it shows an error)
c) No need for creating instance of enclosing class.
d) Only final variables of enclosing method are visible.
e) Can access only static members of the enclosing class.
5) Local class(non-static) block with no static context(class within a method)
a) Accesibility modifiers: Can be only default(ie:no private/public/protected).
b) Defines only non-static members. (ie: if I declare a static variable in the inner class ,it shows an error)
c) Need for creating instance of outer class
d) Only final variables of enclosing method are visible.
e) Can access all members of the enclosing class(whether it is static or not).
6) Anonymous inner classes (non-static)-Same as that of local class(non-static).
7) Anonymous inner classes(static) -Same as that of local class(static).

8) Classes declared within an interface
a)Accesibility modifiers: Can be only default or public(ie:no private/protected).
b) Defines both static & non-static members.
c) Can access both static & non-static variables(declared in interface)�
Of course, all variables declared in an interface are implicitily static.
</pre>
</html>
[This message has been edited by Vinoo Varghese (edited October 02, 2001).]
[This message has been edited by Thomas Paul (edited October 05, 2001).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vinoo,
Just two quick notes:
1. You can declare static variables inside non-static inner classes if they are constants i.e. final static
The following compiles without error.

2. A member class declared in an interface cannot be private or protected but an inner class declared within an interface can be.
The following compiles without error.


Good luck on the 6th!
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited October 04, 2001).]
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic