Chapter 6

Poly-what-ism?

IN THIS CHAPTER

Bullet Hiding or overriding a base class method

Bullet Building abstract classes and methods

Bullet Using ToString()

Bullet Sealing a class from being subclassed

In inheritance, one class adopts the members of another. Thus it's possible to create a class SavingsAccount that inherits data members, such as account id, and methods, such as Deposit(), from a base class BankAccount. That's useful, but this definition of inheritance isn’t sufficient to mimic what’s going on out there in the business world. (See Chapter 5 of this minibook if you don’t know or remember much about class inheritance.)

A microwave oven is a type of oven, not because it looks like an oven, but rather because it performs the same functions as an oven. A microwave oven may perform additional functions, but it performs, at the least, the base oven functions, such as heating food. It’s not important to know what the oven must do internally to make that happen, any more than it’s important to know what type of oven it is, who made it, or whether it was on sale when purchased.

From a human vantage point, ...

Get C# 10.0 All-in-One For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.