サブクラスオブジェクトがスーパークラスを参照する方法は?たとえば、次のようにChildClass
コンストラクタが呼び出される。ここ継承:サブクラスの基本クラスフィールドへのアクセス
public class ParentClass {
public ParentClass() {} // No-arg constructor.
protected String strField;
private int intField;
private byte byteField;
}
public class ChildClass extends ParentClass{
// It should have the parent fields.
}
、タイプParentClass
のオブジェクトが作成され、右?
ChildClassはParentClassオブジェクトからstrField
を継承していますので、何とかParentClass
オブジェクトにアクセスする必要があります(ChildClass
オブジェクト)。
利用superキーワード:P – Sach
これは本当に悪いタイトルです。そこにいくつかのコンテキストを置くことを考えてください – Nishant
私は同意する、(:-)今それは良いです! –