//2005-10-5 22:54
//c08:Parcel9.java
//Using the "instance initializtion" to perform constructor on an anonymous inner class.package c08;public class Parcel9
{
public Destination dest(final String dest,final float price)
{
return new Destination()
{
private int cost;
{
cost=Math.round(price);
if(cost>100)
System.out.println("Over budget");
}
private String label1=dest;
public String readLabel()
{
return label1;
}
int getCost()
{
return cost;
}
};
}
public static void main(String[] args)
{
Parcel9 p=new Parcel9();
Destination d=p.dest("Taniana",101.23f);
//System.out.println(d.getCost());
System.out.println(d.readLabel());
}
}请问怎样在main函数中访问getCost()方法。谢谢