子类对象如何引用超类?例如:继承:从子类访问基类字段
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.
}
这里当ChildClass
构造函数被调用,创建ParentClass
类型的对象,对不对?
ChildClass从ParentClass对象继承strField
,所以它(ChildClass
对象)应该有权访问ParentClass
对象,但是怎么做?
使用super关键字:P – Sach 2013-03-16 17:44:36
这是非常糟糕的称号。考虑在那里放一些背景。 – Nishant 2013-03-16 17:46:20
我同意,(:-)现在更好! – 2013-03-16 19:21:41