package tmp;
public class SellOut {
public float profile_precent=0.1f;
public SellOut(float profile_precent){
this.profile_precent=profile_precent;
}
public static void main(String[] args) {
SellOut a=new SellOut(0.5f);
a.sell(100);
}
public void sell(float cost){
class Apple{
public float cost;
public Apple(float cost){
this.cost=cost;
}
public void price(){
System.out.println("Apple price: "+cost*((float)1+profile_precent));
}
}
Apple a=new Apple(cost);
a.price();
}
}
输出结果:
Apple price: 150.0
知识点:1、局部内部类即为成员方法里面定义的类,它的作用范围只在这个方法体内