本帖最后由 徐卓 于 2013-7-11 20:29 编辑
- class GoodDogTestDrive
- {
- public static void main(String[] args)
- {
- GoodDog one = new GoodDog();
- one.setSize(70);
- GoodDog two = new GoodDog();
- two.setSize(8);
- System.out.println("Dog one:"+ one.getSize());
- System.out.println("Dog two:"+two.getSize());
- one.bark();
- two.bark();
- }
- }
- class GoodDog
- {
- private int size; //实例变量设定为私有
- public int getSize()
- {
- return size;
- }
- public void setSize (int s)
- {
- size = s;
- }
- void bark () {
- if (size>60)
- {
- System.out.println("Wooof! Wooof!");
- }else if (size >14)
- {
- System.out.println("Ruff! Ruff!");
- }else {
- System.out.println("Yip! Yip!");
- }
- }
- }
复制代码 在第24行size = s,是把调入的值赋值给size,于第17行的私有size一样吗 ,求解 |