Protected class-level variable in C#.NET

Define protected class-level variable in C#.NET.

It can be inherited by the classes in the same namespace.

For a protected member, access is limited within the class definition and any class that inherits from the class.

class vehicle {
    protected int i = 0;
    public void vehicleinterior()
    {
        // you can access all public, protected and private members.
        }
}

class car : vehicle
{
    public void carinterior()
    {
         i = 1; // it's legal because it's defined as protected in vehicle class.
         // here you can't access the private members of the vehicle class.
    }
}
Inherit multiple interfaces in C#.NET
Is it possible to inherit multiple interfaces in C#.NET Yes.....
How to prevent your class from being inherited? - C#.NET
C#.NET - How to prevent your class from being inherited? - You can do so by declaring the class public and making the method sealed...
When do we declare a class as abstract in C#.NET?
C#.NET - When do we declare a class as abstract in C#.NET? - When at least one of the methods in the class is abstract...
Post your comment