Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating an inner class

 
chris czinder
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,
I know I'm going to feel dumb when I get an answer to this, but here it goes.
I need to create an inner class and have it encapsulate stuff.
Well uhm....how do you create an inner class. I've looked at documentation here and on sun.java. but I still don't get it.
Any help would be greatly appreciated.
Thanks
chris
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to create an inner class?
Normal non-inner classes can also "encapsulate stuff".
 
chris czinder
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to use an inner class to create get and set methods for 3 instance variables. The inner class will also have a constructor to insantiate an object using the received values of the 3 variables
Chris
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may work well to discuss the details of some example code - perhaps some simple code that you are trying to figure out...
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not saying you don't need an inner class but

I need to use an inner class to create get and set methods for 3 instance variables.

this is not a good reason. The get and set methods you create in an inner class will only be accessable by the outer class. No other class will be able to use them, even if they are declared 'public'.
But here is an example:

Other people can jump in here and explain why this code doesn't really do anything for you.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The get and set methods you create in an inner class will only be accessable by the outer class. No other class will be able to use them, even if they are declared 'public'.
That's not really true. Were the inner class private, then it and its members would not be accessible from outside of the enclosing (outer) class.
[ October 24, 2002: Message edited by: Dirk Schreckmann ]
 
chris czinder
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, Well I only need the Outter class to get the information from the inner class, so that is not a concern. The app i'm writing only has the one class. As far as some code this is what i've got going so far with it.

I know there is more to set and get then that, and i know i need to declare variables, but i understand that. I'm just curious, if i'm setting up the outter inner class thing right.
thanks
Chris
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to write the whole thing to compile it. Just give it a shot.
The only I can see is that you have "Class" instead of "class".
 
chris czinder
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for their input, additional input is always welcome, but I think I've got it figured out. I'll let you all know later

Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic