• 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

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).]
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic