JAVA每日学习日报 7.9

2021-04-22 15:30

阅读:695

标签:pac   对象   dong   str   his   style   inf   load   private   

今天的JAVA,学习的是关于类与对象的知识

不得不说学了C++再来接触这个还挺舒服的,下面是我今天试着写的一个学生类

package hellopeace;

public class Student {
    public String Name; 
    public int Age;
    private boolean Sex; 
    public boolean isSex() {
        return Sex;
    }
    public void setSex(boolean sex) {
        this.Sex = sex;
    }
    public static void main(String[] args) {
        Student ma = new Student();
        ma.Name = "马云 ";
        String isMan = ma.isSex() ? "女" : "男";
        ma.Age = 55;
        System.out.println("姓名:" + ma.Name + "性别:" + isMan + "年龄:" + ma.Age);
        Student dong = new Student();
        dong.Name = "董明珠 ";
        dong.Sex = true;
        dong.Age = 65;
        String isWoman = dong.isSex() ? "女" : "男";
        System.out.println("姓名:" + dong.Name + "性别:" + isWoman + "年龄:" + dong.Age);
    }
}

运行结果

技术图片

 

 

 还有几天C++实训就结束了,等着我啊JAVA!

JAVA每日学习日报 7.9

标签:pac   对象   dong   str   his   style   inf   load   private   

原文地址:https://www.cnblogs.com/Sakuraba/p/13276293.html


评论


亲,登录后才可以留言!