locked
public vs. private methods RRS feed

  • Question

  • Hi
    I am going through the video tutes here, and reading the supplementary material in the PDF, but im still confused about the differences between creating a public, or private method.
    what is the difference ? are they both used, or is one preferred to the other ?
    thanks for any tips.
    DA
    Tuesday, January 24, 2006 10:01 PM

Answers

  • hi,

    think of it as securety permissions and visiblity to others for example if you have

    private stuff >>> then we can't see and we don't  have persmission to know it like your visa card number for example

    public stuff >>> is like your post now we have permission and can see it

    protected stuff >>> just you and your family who can know it and noother one have permission to know it

    when you build a class or method you have to determin the security of this part use private with the methods or fields that will just be used within your class and no other classes have permission to see it

    use public with the things that you want your class to share it with all classes

    use protected with stuff  that you want only the family of this class can see though inheritance

    hope that helps

     

    Tuesday, January 24, 2006 11:59 PM

All replies

  • Dan,

    Private methods can only be called by other methods in the Class.  Only that class can see the method.

    Public methods can be seen and called by other Classes in your project.

     

    Tuesday, January 24, 2006 10:18 PM
  • Hi,

    it depends if:

    1)you want to make these methods accessible without restriction  => Public

    (remember that the Main method is declared public so that Main() can be invoked from any .NET runtime enviroment)

    2)you want to make these methods accessible ONLY by the instance of the class that declares the method  => Private

    (by the container only. so that it's known as the least generous access modifier)

     

    Tuesday, January 24, 2006 11:06 PM
  • hi,

    think of it as securety permissions and visiblity to others for example if you have

    private stuff >>> then we can't see and we don't  have persmission to know it like your visa card number for example

    public stuff >>> is like your post now we have permission and can see it

    protected stuff >>> just you and your family who can know it and noother one have permission to know it

    when you build a class or method you have to determin the security of this part use private with the methods or fields that will just be used within your class and no other classes have permission to see it

    use public with the things that you want your class to share it with all classes

    use protected with stuff  that you want only the family of this class can see though inheritance

    hope that helps

     

    Tuesday, January 24, 2006 11:59 PM