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

2012/5/16

the necessity of public and private

Gazzzah Gazzzah

2012/5/16

#
It seems to be that when making a void or GreenfootImage or some other kind of class within an Actor or something, I don't actually have to specify public/private all the time. Why do I need to?
mjrb4 mjrb4

2012/5/16

#
There's 4 levels of visibility in Java - two are public and private, another is protected and the 4th is "package private". The 4th is different because it has no keyword, it's the "default" visibility per-se, which is what you get if you leave public / private off. Your code may still work when using the default visibility since usually in Greenfoot all your code is in the same package, but unless you're dealing with packages and specifically want package private access for some reason, you should still use pick a visibility modifier for good practice.
You need to login to post a reply.