Software Development  Training Program Zeeshan Hanif
DotNet 3.5-101 Lecture 7 Zeeshan Hanif [email_address] [email_address]
Inheritance What is Inheritance Inherited Members new method virtual and override methods Polymorphism Abstract classes Sealed classes Object class Boxing and Unboxing Interfaces
Inheritance Inheritance is a powerful mechanism that allows a class to inherit functionality from an existing class.  For example, Cat, Dog, both are  kinds of Mammal.  Car and Bus both are kinds of Vehicle
is-a Relationship The is-a relationship is one of specialization. When we say, Dog is-a mammal, means dog is specialized kind of mammal Mammal is generalization kind of Dog
Car Luxury cars Sports Car
Inheritance In object-oriented terminology, sports cars and luxury cars are  derivedclasses  of car class. Similarly, the car class is the  baseclass  of luxury car and sports car.
Example public class Car { public int wheels; public string color; } public class SportsCar  : Car  { public int noOfSeats; }
Inheritance Each derived class  inherits  all variables from the base class. Sports cars and luxury cars both inherits four wheels, gears etc.  Also, each derived class inherits methods from the base class. Luxury cars and sports cars share some behaviors: braking and changing speed, for example.
Inheritance A However, derived classes are not limited to the state and behaviors provided to them by their base class. Derived classes can add more variables and methods. Sports cars have two seats and, some sports cars have an extra set of gears.
Inheritance What is Inheritance Inherited Members new method virtual and override methods Polymorphism Abstract classes Sealed classes Object class Boxing and Unboxing Interfaces

C Sharp Jn (6)

  • 1.
    Software Development Training Program Zeeshan Hanif
  • 2.
    DotNet 3.5-101 Lecture7 Zeeshan Hanif [email_address] [email_address]
  • 3.
    Inheritance What isInheritance Inherited Members new method virtual and override methods Polymorphism Abstract classes Sealed classes Object class Boxing and Unboxing Interfaces
  • 4.
    Inheritance Inheritance isa powerful mechanism that allows a class to inherit functionality from an existing class. For example, Cat, Dog, both are kinds of Mammal. Car and Bus both are kinds of Vehicle
  • 5.
    is-a Relationship Theis-a relationship is one of specialization. When we say, Dog is-a mammal, means dog is specialized kind of mammal Mammal is generalization kind of Dog
  • 6.
    Car Luxury carsSports Car
  • 7.
    Inheritance In object-orientedterminology, sports cars and luxury cars are derivedclasses of car class. Similarly, the car class is the baseclass of luxury car and sports car.
  • 8.
    Example public classCar { public int wheels; public string color; } public class SportsCar : Car { public int noOfSeats; }
  • 9.
    Inheritance Each derivedclass inherits all variables from the base class. Sports cars and luxury cars both inherits four wheels, gears etc. Also, each derived class inherits methods from the base class. Luxury cars and sports cars share some behaviors: braking and changing speed, for example.
  • 10.
    Inheritance A However,derived classes are not limited to the state and behaviors provided to them by their base class. Derived classes can add more variables and methods. Sports cars have two seats and, some sports cars have an extra set of gears.
  • 11.
    Inheritance What isInheritance Inherited Members new method virtual and override methods Polymorphism Abstract classes Sealed classes Object class Boxing and Unboxing Interfaces