我得到了类型测试的封闭实例不可访问。必须使用类型测试错误的封闭实例来限定分配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;
}
}
}
try
Location ob1 = new test().new Location(10.0, 20.0);
Location ob2 = new test().new Location(5.0, 30.0);
需要先创建外部类的实例,然后才能创建内部类的实例
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)