java学习day3

发布时间:2024年01月05日

今天没学啥新东西;来整个活,学到面向对象了,得new一个对象了

代码如下:

public class NewYear {
    private String name;
    private int age;
    private double height;
    private double weight;
    private String type;
    private int money;
    private String boyFriend;
    public String getName() {
        return name;
    }
    public int getAge() {
        return age;
    }
    public double getHeight() {
        return height;
    }
    public double getWeight() {
        return weight;
    }
    public String getType() {
        return type;
    }
    public int getMoney() {
        return money;
    }
    public String getBoyFriend() {
        return boyFriend;
    }
    private NewYear(String name, int age, double height, double weight, String type, int money, String boyFriend){
        this.name=name;
        this.age=age;
        this.height=height;
        this.weight=weight;
        this.type=type;
        this.money=money;
        this.boyFriend=boyFriend;
    }
    public static void main(String[] args) {
        NewYear girl = new NewYear("李华", 18,165,
                100,"甜妹",10000000,
                "奔赴向遇见你的下一个轮回");
        System.out.println("都学计算机了,要学会自己new女友");
        System.out.println("所以新年新对象");
        System.out.println("==========女朋友==========");
        System.out.println("姓名:"+girl.getName());
        System.out.println("年龄:"+girl.getAge());
        System.out.println("身高:"+girl.getHeight());
        System.out.println("体重:"+girl.getWeight());
        System.out.println("类型:"+girl.getType());
        System.out.println("余额:"+girl.getMoney());
        System.out.println("男友:"+girl.getBoyFriend());
    }

}
文章来源:https://blog.csdn.net/2301_81834330/article/details/135387028
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。