| | |
public void close () VS. private void close ()
![]() |
•
•
Join Date: Aug 2008
Posts: 203
Reputation:
Solved Threads: 13
0
#2 19 Days Ago
Hello.
Adding the private modifier to a method means that you can ONLY call it from within that class.
The public modifier means that you can access that method with the dot (.) operator from other classes.
Hope that clears things up =)
Adding the private modifier to a method means that you can ONLY call it from within that class.
The public modifier means that you can access that method with the dot (.) operator from other classes.
Java Syntax (Toggle Plain Text)
public class Foo{ public Foo{ doSomethingInternal(); // Legal (This is the same as this.doSomethingInternal(); doSomethingExternal(); // Legal (This is the same as this.doSomethingExternal(); } public void doSomethingExternal(){/*code*/} private void doSomethingInternal(){/*code*/} }
Java Syntax (Toggle Plain Text)
public class Bar{ public static void main(String[] args){ Foo foo = new Foo(); foo.doSomethingExternal(); // Legal foo.doSomethingInternal(); // NOT Legal } }
Hope that clears things up =)
Last edited by llemes4011; 19 Days Ago at 6:29 pm. Reason: correction
•
•
Join Date: Aug 2008
Posts: 203
Reputation:
Solved Threads: 13
0
#3 19 Days Ago
Good points about the public modifier - You can modify variables in the class through gettor/settor methods. These methods can be called by using the dot (.) operator.
Good points about the private modifier - It allows methods that should ONLY BE CALLED BY THE CLASS (initing vars, handling events, ect) to be non-accessible to anything outside the class. These methods cannot be called by using the dot (.) operator.
(Sorry for double post)
Good points about the private modifier - It allows methods that should ONLY BE CALLED BY THE CLASS (initing vars, handling events, ect) to be non-accessible to anything outside the class. These methods cannot be called by using the dot (.) operator.
(Sorry for double post)
![]() |
Similar Threads
- how to make form disapper not close ( like msn messenger) (C#)
- Panels, different kinds, and how they work together. (Java)
- Getting my data back from my JList (Java)
- Not able to Display image on canvas, want to create game. (Java)
- OleDbDataReader error (C#)
- XML save settings (C#)
- Urgent Help Needed!!!! Plzzz (Java)
- needed big time hw due and late (C)
Other Threads in the Java Forum
- Previous Thread: Unable to expand window
- Next Thread: Help with Array
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql stop string swing testautomation threads transforms tree ui unicode validation windows





