[Solved] I am finding it hard to understand inheritance in C# [closed]


Let’s draw a sketch:

  Person
    Employee  (Employee can be though as a subset of Person)
      Manager (Manager can be though as a subset of Employee)

so every Manager is Employee, every Employee is Person. The sequence is transitive, and thus every Manager is Person. Now, let’s see

  Person alice = new Employee();

You’ve created an Employee instance (new Employee();) and then try to assign it to Person (Person alice =) instance; since every Employee is Person you can do it.

On the contrary:

  Manager cindy = new Employee();

You’ve created an Employee instance and then try to assign it to Manager instance. You can’t do it since there’s no such a rule that every Employee is Manager (Quite the opposite: every Manager is Employee, but not vice versa).

solved I am finding it hard to understand inheritance in C# [closed]