Hi, I'm new to processing and programming and I'm reading "Programming interactivity" by Joshua Noble. There's something I did not understand completely about public and private methods in a class. Public methods can be accessed outside the class, private methods can only be accessed within the class so if I tried to call a private method outside the class I should get an error. Is that right?
So why if I call my private method dream() outside the class I do not get any error? Here's my code:
As calsign said, the game is biased in Processing, because all classes defined in .pde files are internal to the main class (named after the sketch name) and these children classes have special access rules to their parent's elements. You can see the real Java code generated by Processing in a .java file created when you export a sketch. If you want to see the real behavior of a separate class, put that class in a .java file in your sketch. It won't be nested.
That's why we use a somewhat relaxed coding style in Processing, rarely using private, protected or public, as most sketches are small and usually fit in one file only, with little code reusing. Of course, libraries use a stricter style, in general.
Ok. That make sense. I used an external .java file for my class and now Processing returns an arror when I try to call a private method in my sketch. I'm just a newbie so I think I will not use private methods at the moment but I wanted to uderstand how do they work. Thaks a lot!
Leave a comment on stainboy's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic