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、局部内部类即为成员方法里面定义的类,它的作用范围只在这个方法体内
本文探讨了Java中局部内部类的定义及其在方法参数中的应用,通过实例展示了如何利用局部内部类来扩展方法的功能,特别关注了类Apple作为方法参数的例子。
629

被折叠的 条评论
为什么被折叠?



