public void close () VS. private void close ()

Reply

Join Date: Oct 2009
Posts: 29
Reputation: COKEDUDE is an unknown quantity at this point 
Solved Threads: 1
COKEDUDE COKEDUDE is offline Offline
Light Poster

public void close () VS. private void close ()

 
0
  #1
20 Days Ago
Can someone please explain what both of these mean and the good details about them. Please also explain the parameters of how to use it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training
 
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.
  1. public class Foo{
  2. public Foo{
  3. doSomethingInternal(); // Legal (This is the same as this.doSomethingInternal();
  4. doSomethingExternal(); // Legal (This is the same as this.doSomethingExternal();
  5. }
  6. public void doSomethingExternal(){/*code*/}
  7. private void doSomethingInternal(){/*code*/}
  8. }
  1. public class Bar{
  2. public static void main(String[] args){
  3. Foo foo = new Foo();
  4. foo.doSomethingExternal(); // Legal
  5. foo.doSomethingInternal(); // NOT Legal
  6. }
  7. }

Hope that clears things up =)
Last edited by llemes4011; 20 Days Ago at 6:29 pm. Reason: correction
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training
 
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)
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC