我得到了类型测试的没有封闭实例是可访问的。必须使用类型测试错误的封闭实例来限定分配,Location ob1 = new Location(10.0, 20.0);
我不确定为什么..
package pkg;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Location ob1 = new Location(10.0, 20.0);
Location ob2 = new Location(5.0, 30.0);
ob1.show();
ob2.show();
ob1 = ob1.plus(ob2);
ob1.show();
return;
}
public class Location // an ADT
{
private double longitude, latitude;
public Location(double lg, double lt) {
longitude = lg;
latitude = lt;
}
public void show() {
System.out.println(longitude + " " + latitude);
}
public Location plus(Location op2) {
Location temp = new Location(0.0, 0.0);
temp.longitude = op2.longitude + this.longitude;
temp.latitude = op2.latitude + this.latitude;
return temp;
}
}
}