c sharp jn (6)

11
Zeeshan Hanif Software Development Training Program Zeeshan Hanif

Upload: jahanullah

Post on 25-May-2015

340 views

Category:

Automotive


1 download

TRANSCRIPT

Page 1: C Sharp Jn (6)

Zeeshan Hanif

Software Development Training Program

Zeeshan Hanif

Page 2: C Sharp Jn (6)

Zeeshan Hanif

DotNet 3.5-101 Lecture 7

Zeeshan [email protected]

[email protected]

Page 3: C Sharp Jn (6)

Zeeshan Hanif

Inheritance What is Inheritance Inherited Members new method virtual and override methods Polymorphism Abstract classes Sealed classes Object class Boxing and Unboxing Interfaces

Page 4: C Sharp Jn (6)

Zeeshan Hanif

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

Page 5: C Sharp Jn (6)

Zeeshan Hanif

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

Page 6: C Sharp Jn (6)

Zeeshan Hanif

Car

Luxury cars

Sports Car

Page 7: C Sharp Jn (6)

Zeeshan Hanif

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.

Page 8: C Sharp Jn (6)

Zeeshan Hanif

Example

public class Car {public int wheels;public string color;

}public class SportsCar : Car {

public int noOfSeats;}

Page 9: C Sharp Jn (6)

Zeeshan Hanif

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.

Page 10: C Sharp Jn (6)

Zeeshan Hanif

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.

Page 11: C Sharp Jn (6)

Zeeshan Hanif

Inheritance What is Inheritance Inherited Members new method virtual and override methods Polymorphism Abstract classes Sealed classes Object class Boxing and Unboxing Interfaces