rl

Java对象介绍与实例

 

 

package tyu;

public class Person {
    public int id;
    public String name;
    public int age;
    public String city;
    public String introduce() {
        String songs = null;
        return "我是" + id + ",叫" + name + ", 今年" + age + "岁, 来自" + city +"en "+songs;
    }  
    public Person(int id,String name,int age,String city) {
        this.id=id; 
        this.name=name;
        this.age=age;
        this.city=city;
    }
}

 

package tyu;

public class DemoPerson {
     public static void main(String[] args) {
            Person p1=new Person(110001,"刘备",43,"幽州涿郡涿县");
            Person p2=new Person(110002,"关羽",35,"河东郡解县");
            Person p3=new Person(110003,"张飞",25,"幽州涿郡");
            Person p4=new Person(110004,"诸葛亮",20,"徐州琅琊阳都");
           
            System.out.println(p1.introduce());
            System.out.println(p2.introduce());
            System.out.println(p3.introduce());
            System.out.println(p4.introduce());
     }
            

}

 

转载于:https://www.cnblogs.com/gaojie77/p/7750751.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值