Skip to Content
プログラミングC# 第8版
book

プログラミングC# 第8版

by Ian Griffiths, 木下 哲也, 鈴木 幸敏
June 2021
Intermediate to advanced
800 pages
13h 5m
Japanese
O'Reilly Japan, Inc.
Content preview from プログラミングC# 第8版

6章継承

 C#のクラスは、継承(inheritance)というオブジェクト指向言語で一般的なコード再利用メカニズムに対応しています。クラスを記述するときには基底クラス(base class)を指定できます。クラスは、基底クラスから派生することになります。つまり、そのクラスには、追加したメンバに加えて基底クラスに属するすべての要素が含まれます。

 クラスは単一継承(single inheritance)のみに対応しています(したがって、1つの基底クラスだけを指定できます)。インターフェイスは多重継承(multiple inheritance)の機能を提供します。値型は継承に対応していません。値型は通常参照で使われないので、継承の主な利点である実行時ポリモーフィズム(polymorphism:多態性)を活かせないためです。いくつかの言語で見られるように、継承は必ずしも値的な振る舞いと相容れないわけではありませんが、問題を引き起こすことが多々あります。例えば、派生型の値を基底型の変数に代入すると、派生型で追加したすべての要素が失われてしまう結果となります。この問題はスライシング(slicing)と呼ばれています。C#は継承を参照型に限定してこの問題を回避しています。派生型の変数を基底型の変数に代入するときには、オブジェクトそのものではなく参照のコピーを行っているため、オブジェクトは変化しません。基底クラスがオブジェクトを複製する方法を提供するが、派生クラスでそれを拡張する方法を提供しない(あるいは提供しても拡張に失敗する)場合にのみスライシングが発生します。

 クラスは例6-1に示す構文によって基底クラスを指定します。基底型はクラス名に続くコロンの後ろに書きます。この例は、プロジェクトの他の場所か使用するライブラリの1つで ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

動かして学ぶ量子コンピュータプログラミング ―シミュレータとサンプルコードで理解する基本アルゴリズム

動かして学ぶ量子コンピュータプログラミング ―シミュレータとサンプルコードで理解する基本アルゴリズム

Eric R. Johnston, Nic Harrigan, Mercedes Gimeno-Segovia, 北野 章, 丸山 耕司
ユーザーストーリーマッピング

ユーザーストーリーマッピング

Jeff Patton, 川口 恭伸, 長尾 高弘
Unityによるモバイルゲーム開発 ―作りながら学ぶ2D/3Dゲームプログラミング入門

Unityによるモバイルゲーム開発 ―作りながら学ぶ2D/3Dゲームプログラミング入門

Jon Manning, Paris Buttfield-Addison, 鈴木 久貴, あんどうやすし, 江川 崇, 安藤 幸央, 高橋 憲一

Publisher Resources

ISBN: 9784873119366Other