首页 > 其他分享 >NoStaticDemo

NoStaticDemo

时间:2024-09-23 14:22:14浏览次数:9  
标签:name age NoStaticDemo nation Person public String


package com.shrimpking.t5;

import java.sql.SQLOutput;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2024/9/15 20:39
 */
class Person{
    String name;
    String nation;
    int age;

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

    public String talk(){
        return String.format("我是%s,今年%d岁,来自%s",this.name,this.age,this.nation);
    }
}

public class NoStaticDemo
{
    public static void main(String[] args)
    {
        //没有静态属性的不便
        Person p1 = new Person("zhang","china",25);
        Person p2 = new Person("wang","china",30);
        Person p3 = new Person("zhao","china",35);

        System.out.println(p1.talk());
        System.out.println(p2.talk());
        System.out.println(p3.talk());
    }
}

标签:name,age,NoStaticDemo,nation,Person,public,String
From: https://blog.51cto.com/u_15356972/12089179

相关文章