【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; } } }
第十题

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 的区别

许可协议:
CC BY 4.0