Reputation: 8599
I have 3 concrete classes named ClassA (that is built-in System.Web.UI.Page class), ClassB, and ClassC (see codes below). ClassC is a dervived class of ClassB that is in turn is a derived class of ClassA. ClassB has its own members. My question is how can ClassC invoke or access members (public properties, public methods) of ClassB? How are the scopes of classes solved in source codes of ClassC to avoid ambiguity? Thanks in advance.
Some codes:
// ClassA = System.Web.UI.Page
public class System.Web.UI.Page {
// built-in class
}
public class ClassB : System.Web.UI.Page {
// some own properties
public bool IsUserLoginNameVisible { get; set; }
// some own methods
public void GetLoginUsers()
{
}
}
public class ClassC : ClassB {
public int NumberOfLoginUsers()
{
// how can I invoke method "GetLoginUsers()" from ClassB in here?
// base.GetLoginUsers() ???
}
public bool CheckToSeeUserLoginNameVisible()
{
// how can I access property "IsUserLoginNameVisible" from ClassB in here?
// base.IsUserLoginNameVisible ???
}
}
Upvotes: 0
Views: 199
Reputation: 887449
Derived classes inherit all accessible members from their base class.
You can call them just like any other instance method.
The base
keyword will force the call to resolve to the (immediate) base class' definition, even if your class shadows it, or your or derived class overrides it.
Upvotes: 5