7 inheritance and polymorphism

20
Inheritance and Polymorphism [email protected] Programming in C#

Upload: tuan-ngo

Post on 08-May-2015

1.268 views

Category:

Technology


9 download

TRANSCRIPT

Page 1: 7   inheritance and polymorphism

Inheritance and Polymorphism

[email protected]

Programming in C#

Page 2: 7   inheritance and polymorphism

Inheritance

Page 3: 7   inheritance and polymorphism

Inheritance

Page 4: 7   inheritance and polymorphism

Purpose of Inheritance

reuse common methods and attributes among classes without

recreating them

Generalization

Specialization

Extension

Page 5: 7   inheritance and polymorphism

Implementing Inheritance

https://gist.github.com/2358793

Page 6: 7   inheritance and polymorphism

protected

https://gist.github.com/2358827

Page 7: 7   inheritance and polymorphism

based

access the variables and methods of the base class from the derived class

cannot use for invoking the static method

Page 8: 7   inheritance and polymorphism

new

hide the methods or variables of the base class

https://gist.github.com/2358859

Page 9: 7   inheritance and polymorphism

Constructor Inheritance

https://gist.github.com/2358859

Page 10: 7   inheritance and polymorphism

Method overriding

Page 11: 7   inheritance and polymorphism

Method Overriding allows the derived class to override or redefine the methods of the base class.

Page 12: 7   inheritance and polymorphism

virtual & override virtual in base class

override in derived class

Page 13: 7   inheritance and polymorphism

Question?

https://gist.github.com/2366263

Page 14: 7   inheritance and polymorphism

Question?

https://gist.github.com/2366821

Page 15: 7   inheritance and polymorphism

Sealed Classes

Page 16: 7   inheritance and polymorphism

Sealed

prevent inheritance

https://gist.github.com/2366688

Page 17: 7   inheritance and polymorphism

Purpose of Sealed Classes

Page 18: 7   inheritance and polymorphism

Polymorphism

Page 19: 7   inheritance and polymorphism

Overriding & Overloading

Page 20: 7   inheritance and polymorphism

Compile-time & Run-time Polymorphism