Results 1 to 6 of 6

Thread: public, private, protected access modifiers in OOP

  1. #1
    Join Date
    Jan 2011
    Posts
    27

    public, private, protected access modifiers in OOP

    I am not a big programmer, In fact I have just started learning about the object oriented programming and I have gone through some programs written in different languages but these three words called as access modifier are used there. Now I don't get that somewhere they use public and somewhere they use private or protected. I guess there would be no difference between the private and protected. I didn't got this concept properly.

  2. #2
    Join Date
    Apr 2009
    Posts
    488

    Re: public, private, protected access modifiers in OOP

    For classes, it should have methods that can use any object of such a class. In our example, the init (), show () and set (). On the other hand, data should be encapsulated yes, that one can not directly access it. For these kinds of differences, there are three key words, public (on the method / attribute can be accessed from anywhere by), private (method / attribute is accessed, only the defining class must in the exactly ) and "protected `` (from the class and all derived classes can be accessed on the method / attribute). In addition, all objects must have all the features of an object class in the same class of access (including private-defined).

  3. #3
    Join Date
    May 2009
    Posts
    511

    Re: public, private, protected access modifiers in OOP

    . NET, there are five access levels. The first level of access each provides unlimited access. It is referred to as public. All defined as public classes, methods or properties are visible to any other code. The classes for ASP.NET pages, for example, be defined as public, as they are accessed on needs to display the page. The exact opposite of this public access is private. To keep the access limited to its own class. In a private defined properties or methods can be accessed only by code, the class is contained in them. From derived classes or other elements can not be accessed in private.

  4. #4
    Join Date
    May 2009
    Posts
    543

    Re: public, private, protected access modifiers in OOP

    Between public and private, there are other access levels. The protected (protected) level allows properties and methods that are defined as protected, within their own class and all of these derived classes are visible. The next level is in VB.NET with a friend, called in C # with internal. It says that properties and methods that are defined or internal as a friend, all classes within its own assembler code can be accessed by all. This plane can be combined with protected to define properties and methods that all derived classes and all classes are available to the assembler within. It's called common or protected friend / internal, since both approaches are supported.

  5. #5
    Join Date
    May 2009
    Posts
    529

    Re: public, private, protected access modifiers in OOP

    Be careful not to confuse between the static keyword and access modifiers.

    1. A member of a class can be:
    • linked to class => static
    • bound to the instance => no keyword


    2. A member of a class can also be:
    • visible only by the class => private
    • visible to the whole package => no keyword
    • visible to the whole package, and the subclasses within the heritage (*) => protected
    • visible to everyone => public

  6. #6
    ismail12 Guest

    Re: public, private, protected access modifiers in OOP

    Hello,

    1. private - Only the current class will have access to the field or method.

    2. protected - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method.

    3. public - Any class can refer to the field or call the method.

Similar Threads

  1. Difference between Public and Private Cloud
    By Abi.RauT in forum Technology & Internet
    Replies: 4
    Last Post: 30-05-2012, 03:10 PM
  2. Can't change network settings from public to private
    By Henri@ksen in forum Vista Help
    Replies: 1
    Last Post: 02-04-2012, 02:11 AM
  3. Settings up public or private network and ICS
    By aNGRY gANESHAN in forum Vista Help
    Replies: 8
    Last Post: 20-03-2012, 12:17 AM
  4. problem identification ssh public key private on mac os x
    By Hugo Boss in forum Networking & Security
    Replies: 2
    Last Post: 30-03-2009, 02:36 PM
  5. What are the different types of access modifiers in JAVA?
    By Bhim in forum Software Development
    Replies: 4
    Last Post: 25-02-2009, 09:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,243,146.54190 seconds with 17 queries