0

ですから、私はこの冬にプログラミング試験を受けています。私の課題の1つは、プログラミングの例を使用せずに、拡張機能とは何かを説明することです。

今、私はそれが何であるかを知っていますが、言葉で説明するのは難しいと思いますが、どのように説明しますか?Plane あなたがextends のように、これはあなたがクラスの一部であり、あなたのオブジェクトだけが見ることができる追加情報をクラスに追加できることを意味Vehicleします。

どう説明しextendsますか?

4

2 に答える 2

3

The extends keyword in Java has several roles, and it depends on what you extends. If C is the entity you wish to extend.

  • You cannot extend it at all if C is a non abstract class and is final;

  • If C is a non-final, non-abstract class:

    • you can extend it so as to add constructors;
    • you can override any methods of C which are not declared final;
    • you can define additional instance variables, methods etc.
  • If C is an abstract class, and you provide a concrete (ie, non abstract) implementation of it:

    • you must provide constructors which call this abstract class' constructors -- all of them;
    • you must provide implementations of methods which are declared abstract in the extended class;
    • you may override implementations of methods of this class which are not abstract;
    • you cannot override implementations of methods in this class which are declared final;
    • you may add additional constructors, instance variables etc;
  • If C is an interface:

    • you can only declare an interface extending another; you cannot implement a class extending an interface (that is implements).

And, more generally, you can implement several interfaces but only extend one class/abstract class (Java does not have multiple inheritance).

Answer certainly to be edited, feel free to add comments/questions/etc

于 2012-12-25T15:51:15.523 に答える
1

You can find examples all around you..... eg:Animals and different variety of animals Vehicles, with different vehicles having some common properties and some specific properties. Shapes with common properties like area, perimeter etc, where different shapes calculate these functions differently.

于 2012-12-25T15:17:23.177 に答える