练习13——static方法

1、TestSportsman


package test3;

/**
 * 〈一句话功能简述〉<br> 
 * 〈static的讲解应用〉
 *
 * @author abu
 * @create 2019/7/16
 * @since 1.0.0
 */
public class TestSportsMan {
    public static void main(String[] args){
        SportsMan sm1 = new SportsMan("张怡宁", 24);
        SportsMan sm2 = new SportsMan("许昕", 24);
        sm1.nation = "China";

        System.out.println(sm1);
        System.out.println(sm2);

    }

}
class SportsMan{
    String name;
    int age;
    static String nation;


    @Override
    public String toString() {
        return "SportsMan{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", nation='" + nation + '\'' +
                '}';
    }

    public SportsMan() {
    }

    public SportsMan(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public SportsMan(String name, int age, String nation) {
        this.name = name;
        this.age = age;
        this.nation = nation;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNation() {
        return nation;
    }

    public void setNation(String nation) {
        this.nation = nation;
    }
}

2、Circle

public class TestCircle {
    public static void main(String[] args){
        Circle1 c1 = new Circle1(2);
        Circle1 c2 = new Circle1(4);
        System.out.println(Circle1.getTotal());
        Circle1.show();
        c1.setInfo("我是漂亮的圆");
        Circle1.show();

    }

}
class Circle1{
    private double radius;
    private static String info = "我是圆";
    private static int total = 0;

    public Circle1(double radius){
        this.radius = radius;
        total ++;
    }

    public static int getTotal() {
        return total;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }
    public static void show(){
        System.out.println(info);
    }


    @Override
    public String toString() {
        return "Circle1{" +
                "radius=" + radius +
                ", info='" + info + '\'' +
                '}';
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值