为了账号安全,请及时绑定邮箱和手机立即绑定

5-2习题代码的实现,不知行不行,望大家给点建议!!

标签:
Java

package Test2;

import java.util.Scanner;

public class Intail extends Human {
static Human ch= new Chinese();
static Human am = new American();
static Human ger = new Germany();

public static void main(String[] args) {
    System.out.println("请输入您要查询的国家");
    Scanner input = new Scanner(System.in);
    String  words = input.next();
 switch (words) {
case "Chinese":
   ch.speak();
    break;
case"American":
    am.speak();
    break;
case"Germany":
    ger.speak();
    break;

default:
    System.out.println("您的输入有问题!!");
    break;
}

}
}

package Test2;

public class Human{
public String skilColor ;
public String liveLocation ;
public String language;
public String countryName;

public void speak(){
    System.out.println("人可以用语言交流");
}

}

package Test2;

public class Chinese extends Human {
public String skilColor = "黄色";
public String liveLocation= "亚洲" ;
public String language= "汉语";
public String capital = "北京";

@Override
public void speak() {
    // TODO Auto-generated method stub
          System.out.println("chinese的基本资料"); 
          System.out.println("skilColor:"+skilColor);
          System.out.println("liveLocation:"+liveLocation);
          System.out.println("language:"+language);
          System.out.println("capital"+capital);
}

}

package Test2;

public class American extends Human {
public String skilColor = "白色,黑色,黄色" ;
public String liveLocation ="北美洲";
public String language= "English";
public String capital ="华盛顿";
@Override
public void speak() {
// TODO Auto-generated method stub
System.out.println("American的基本资料");
System.out.println("skilColor:"+skilColor);
System.out.println("liveLocation:"+liveLocation);
System.out.println("language:"+language);
System.out.println("capital:"+capital);
}

}

package Test2;

import java.security.PublicKey;

public class Germany extends Human {
public String skilColor = "白色";
public String liveLocation= "欧洲中部" ;
public String language ="German";
public String capital ="柏林";

@Override
public void speak() {
    // TODO Auto-generated method stub
      System.out.println("Germany的基本资料"); 
    System.out.println("skilColor:"+skilColor);
    System.out.println("liveLocation:"+liveLocation);
    System.out.println("language:"+language);
    System.out.println("capiyal"+ capital);
}

}

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消