1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu What Is Inheritance? ppt

1 333 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề What Is Inheritance?
Trường học Standard University
Chuyên ngành Computer Science
Thể loại Tài liệu
Thành phố Standard City
Định dạng
Số trang 1
Dung lượng 21,2 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

There is generally a lot of confusion among programmers as to what inheritance is.. Similarly, we say that you inherit half of your genes from your mother and half of your genes from you

Trang 1

What Is Inheritance?

There is generally a lot of confusion among programmers as to what inheritance is Part

of this trouble stems from the fact that the word “inheritance” itself has several subtly different meanings If someone bequeaths something to you in a will, you are said to inherit it Similarly, we say that you inherit half of your genes from your mother and half

of your genes from your father Both of these uses of the word inheritance have very little

to do with inheritance in programming

Inheritance in programming is all about classification—it's a relationship between

classes For example, when you were at school, you probably learned about mammals, and learned that horses and whales are examples of mammals Each does everything that

a mammal does (it breathes air, gives birth to live young, and so on), but also has its own special features (a horse has hooves, unlike a whale)

In Microsoft Visual C#, you could model this by creating two classes, one called

Mammal and one called Horse, and declare that Horse inherits from Mammal The

inheritance would model that there is a relationship and would capture the fact that all horses are mammals Similarly, you could also declare a class called Whale that also inherits from Mammal Common functionality (such as breathing and giving birth) could

be placed in the Mammal class; properties such as hooves or fins should be placed in the Horse or Whale class as appropriate

 

Ngày đăng: 15/12/2013, 00:15

w