| | |
public void close () VS. private void close ()
![]() |
•
•
Join Date: Aug 2008
Posts: 205
Reputation:
Solved Threads: 13
0
#2 20 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; 20 Days Ago at 6:29 pm. Reason: correction
•
•
Join Date: Aug 2008
Posts: 205
Reputation:
Solved Threads: 13
0
#3 20 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 3d @param affinetransform android api applet application arc arguments array arrays automation banking binary bluetooth byte chat chatprogramusingobjects class client code color compare component count database design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong problem producer program programming project projectideas read recursion reference replaysolutions rim scanner server set size sms sort sql string swing terminal threads transforms tree ui unicode validation web windows





