| | |
public void close () VS. private void close ()
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 207
Reputation:
Solved Threads: 13
0
#2 30 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; 30 Days Ago at 6:29 pm. Reason: correction
•
•
Join Date: Aug 2008
Posts: 207
Reputation:
Solved Threads: 13
0
#3 30 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 |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu windows working





