【java学习】第六天(作业3)

quange 2022-4-15 62 4/15

第九题

【java学习】第六天(作业3)

package com.quange.homework;

public class Homework09 {
    public static void main(String[] args) {
        LabeledPoint black = new LabeledPoint("Black", 12323, 23123);
    }

    // 父类 Point类
    static class Point{
        private int x;
        private int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    // 子类
    static class LabeledPoint extends Point{
        private String label;

        public LabeledPoint(String label, int x, int y) {
            super(x, y);
            this.label = label;
        }
    }
}

 

第十题

【java学习】第六天(作业3)

package com.quange.homework;

public class Homework10 {
    public static void main(String[] args) {
        Doctor doctor = new Doctor("tom", 20, "java", '男', 2000);
        Doctor doctor1 = new Doctor("tom", 20, "java", '男', 2000);
        System.out.println(doctor.equals(doctor1));

    }

    static class Doctor{
        private String name;
        private int age;
        private String job;
        private char gender;
        private double sal;

        public Doctor(String name, int age, String job, char gender, double sal) {
            this.name = name;
            this.age = age;
            this.job = job;
            this.gender = gender;
            this.sal = sal;
        }

        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 getJob() {
            return job;
        }

        public void setJob(String job) {
            this.job = job;
        }

        public char getGender() {
            return gender;
        }

        public void setGender(char gender) {
            this.gender = gender;
        }

        public double getSal() {
            return sal;
        }

        public void setSal(double sal) {
            this.sal = sal;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Doctor doctor = (Doctor) o;
            return age == doctor.age && gender == doctor.gender && Double.compare(doctor.sal, sal) == 0 ;
        }

    }
}
true

进程已结束,退出代码0

== 和 equals 的区别

【java学习】第六天(作业3)

- THE END -
最后修改:2022年4月15日
0

版权声明:
一、本站致力于为软件爱好者提供国内外软件开发技术和软件共享,着力为用户提供优资资源。
二、本站提供的所有下载文件均为网络共享资源,请于下载后的24小时内删除。如需体验更多乐趣,还请支持正版。
三、我站提供用户下载的所有内容均转自互联网。如有内容侵犯您的版权或其他利益的,请编辑邮件并加以说明发送到站长邮箱。站长会进行审查之后,情况属实的会在三个工作日内为您删除。

共有 0 条评论