我们可以在非派生类中使用 super 关键字吗?(Sun Certified Programmer for Java 2 第 7 章中有这样的代码)。在这里,它用于OfficeRoom 类,它不是子类。
1st question example code:
Building.Java
public class Building
{
long length;
long width;
OfficeRoom [] officeRooms; // The building has number of rooms
public Building (long len,long wid,OfficeRoom [] ors)
{
length = len;
width = wid;
officeRooms = ors;
}
public long area()
{
return length * width;
}
}
OfficeRoom.java
public class OfficeRoom
{
long length;
long width;
public Office(long len,wid)
{
super(len,wid) //What is the job of super here?? It is not inside a subclass??
}
public long area()
{
return length * width;
}
}
有可能还是书上写错了?