创建一个名为Apple的类,一个私有的成员变量int price。在构造函数中初始化该参数,创建一个名为int getValue(int weight) 方法,返回苹果价值(price*weight);
例如:
测试 | Result |
---|
Apple a =new Apple(5); System.out.println(a.getValue(10)); | 50 |
class Apple{private int price;Apple(int price){this.price=price;}public void Apple(int prive){this.price=price;}public int getValue(int weight){return price*weight;}
}