面向对象调用方法dog and penguin (三)

package Demo1;


import java.util.Scanner;


public class Demo2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Demo demo = new Demo();
Demo1 newdemo = new Demo1();
System.out.println("请选择宠物");
System.out.println("1.拉布拉多犬 \t2.Q仔");
switch (input.nextInt()) {
case 1:
demo.Dog();
break;
case 2:
System.out.println("请选择Q仔性别      1.Q仔    2.Q妹");
int Sex = input.nextInt();
if(Sex==1){
newdemo.sex="Q仔";
}else{
newdemo.sex="Q妹";
}
newdemo.penguin();
break;
default:
System.out.println("请输入正确数子.");
break;
}
}
}

猜你喜欢

转载自blog.csdn.net/yehaotianyhy/article/details/79403293