This site requires JavaScript, please enable it in your browser!
Greenfoot back
Kartoffelbrot
Kartoffelbrot wrote ...

2013/8/23

Methods accessable for one specific class

Kartoffelbrot Kartoffelbrot

2013/8/23

#
Can I make methods accessable for only one specific class (and the class in which the method is)?
Gevater_Tod4711 Gevater_Tod4711

2013/8/23

#
In greenfoot it's not possible because in greenfoot you have only one package. If you programm in eclipse or any other editor you can have more packages. Using the default (or package-private) modifier (instead of public, private or protected you just have no modifier) the mehtod you declared is only visible in the class itselves and in all classes that are in the same package. If only two classes are in the package there is only one class which is able to access this method (or field). But in greenfoot you can't declare more packages. You have only one package and so it's not possible.
Kartoffelbrot Kartoffelbrot

2013/8/23

#
Thank you
danpost danpost

2013/8/23

#
If the method is 'protected' and the other class you wish to use it in extends the class the method is in, then only those two classes will be able to use the method. However, this may not be what you wanted, especially if you are subclassing that class also. Out of curiousity, what reason(s) do you have for wanting this requirement?
Kartoffelbrot Kartoffelbrot

2013/8/24

#
I have a class called Entity and a class World. The setWorld method in Entity should be only usable for the World. It's using it in it's methods addObject and removeObject.
You need to login to post a reply.