Can i access Private member in derived class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adithi
    New Member
    • Feb 2008
    • 2

    Can i access Private member in derived class

    A Variable is declared as "Private" in one class in C#.
    Can i access this same variable in other class which is derived by this?

    For eg:
    public class Teacher
    {
    private string Name="ABC";

    }

    Public class Student:Teacher
    {
    in this class can i access "Name" variable which was declared in Teacher Class?
    }
  • mankz
    New Member
    • Feb 2008
    • 2

    #2
    Originally posted by adithi
    A Variable is declared as "Private" in one class in C#.
    Can i access this same variable in other class which is derived by this?

    For eg:
    public class Teacher
    {
    private string Name="ABC";

    }

    Public class Student:Teacher
    {
    in this class can i access "Name" variable which was declared in Teacher Class?
    }
    Use the protected modifier if you want to access the member, also try googling first... this link took me < 4 seconds to find for ya :)

    All types and type members in C# have an accessibility level that controls whether they can be used from other code. Review this list of access modifiers.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      It also would have taken <4 seconds if you actually just "tried it", since you already had sample code created.

      Comment

      Working...