C#の基本クラスと派生クラスとは何ですか?
クラスは複数のクラスまたはインターフェースから派生させることができます。つまり、複数の基本クラスまたはインターフェースからデータと関数を継承できます。
たとえば、次の派生クラスを持つ車両ベースクラス。
Truck Bus Motobike
派生クラスは、基本クラスのメンバー変数とメンバーメソッドを継承します。
同様に、Shapeクラスの派生クラスは、次の例のようにRectangleにすることができます。
例
using System;
namespace Program {
class Shape {
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
protected int width;
protected int height;
}
// Derived class
class Rectangle: Shape {
public int getArea() {
return (width * height);
}
}
class Demo {
static void Main(string[] args) {
Rectangle Rect = new Rectangle();
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
Console.WriteLine("Total area: {0}", Rect.getArea());
Console.ReadKey();
}
}
} 出力
Total area: 35
-
Javaのさまざまなタイプのクラスは何ですか?
Javaのクラスの種類 具体的なクラス 抽象メソッドを持たない通常のクラス、または親クラスまたはインターフェースのすべてのメソッドの実装を持ち、独自のメソッドを持つクラスは具象クラスです。 例 public class Concrete { // Concrete Class static int product(int a, int b) { return a * b; } public static void main(String args[]) { &n
-
Pythonの基本オーバーロードメソッドとは何ですか?
Pythonクラスは、オブジェクト指向プログラミングパラダイムのすべての標準機能を提供します。クラス継承メカニズムにより、複数の基本クラスが可能になります。派生クラスは、その基本クラスの任意のメソッドをオーバーライドでき、メソッドは同じ名前の基本クラスのメソッドを呼び出すことができます。