Example
We start with an example:
We start with an example:
class A
{
void Hello()
{
Console.WriteLine(―Hello, World!‖);
}
}
class B:A
{
void Hai()
{
Console.WriteLine(―Hai to all!‖);
}
}
- In the above example, we have two classes called " A " and " B ". The inheritance relationship has been established between these classes. Now, the " A " class is called as "Super " class and " B " class is called as "Sub" class. All the members of "A" class are exactly copied into "B" class. Finally, whenever you construct an object for the "B" class, you can access both "Hello()" method and "Hai()" method also from that object. This is what we learned up-to-now.
- But sometimes, some of the super class members may not be accessible directly from the sub class‘s object. This kind of nature depends on the "access modifiers", we use in the super class, while we declare the super class members.
No comments:
Post a Comment