Tips

今日のIT英語 Lesson8「What Is Inheritance?」

今日のIT英語 Lesson8「What Is Inheritance?」

今日のIT英語 Lesson8「What Is Inheritance?」

今回も前回に引き続き、「Oracle」の「Java tutorial」を読み解きながら、”継承”って何?ということを英語で説明できるようになりましょう。

Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear).

異なるオブジェクトでも互いに共通する部分を持っていることがあります。たとえば、マウンテンバイク、ロードバイク、タンデムバイク、といったものはどれも速度、回転数、ギアといった共通の特徴をもっています。

Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

さらにこれらはそれぞれ独自の特徴も持っています。たとえばタンデムバイクはシートとハンドルバーが2セットある、ロードバイクはドロップハンドルである、マウンテンバイクはチェーンリングを多くもっていたり、より低いギアを持っていたりします。

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

オブジェクト指向では、ほかのクラスから自クラスに「継承(inherit)」するということが可能です。上記の例においては、自転車というクラスを継承したマウンテンバイク、ロードバイク、タンデムバイクというクラスを定義することができます。Javaにおいて、それぞれのクラスは直接的には1つのスーパークラス(親クラス)をもつことを許可されており、1スーパークラスを継承するサブクラスはいくつあってもかまいません。

引用文献:The Java™ Tutorials

いかがだったでしょうか?前回のクラスという概念は、継承することができるということがわかりました。
これにより、共通部分はひとつのクラスにまとめることができますし、個別の処理はサブクラスに追加で記述してあげればよいということですよね。ちなみに、スーパークラスを複数持つ継承のことを多重継承といいますが、Javaでは多重継承は認められていません。

Classes are not allowed to inherit some state and behavior from other classes.

Recent News

Recent Tips

Tag Search