package abstractClasses;

import java.time.LocalDate;

/**
* Created by xkfx on 2016/12/20.
*/
public class Employee extends Person{
private String name;
private double salary;
private LocalDate hireDay; public Employee(String name, double salary, int year, int month, int day){
super(name);
this.salary = salary;
hireDay = LocalDate.of(year, month, day);
} public double getSalary(){
return salary;
} public LocalDate getHireDay(){
return hireDay;
} public String getDescription(){
return String.format("an employee with a salary of $%.2f", salary);
} public void raiseSalary(double byPercent){
double raise = salary * byPercent / 100;
salary += raise;
} public boolean equals(Object otherObject){
if(this == otherObject)
return true;
// 指向同一个对象就什么事情都没有了。
if(otherObject == null)
return false;
// 所比较对象指向null也不用比了。
if(this.getClass() != otherObject.getClass())
return false;
// 经以上比较可知,两个引用不指向同一个对象,并且两对象属于同类。
Employee other = (Employee)otherObject;
// 经过类型强制转化,才能能够访问otherObject对象具体类的实例域 // 测试实例域是否相同
return name.equals(other.name) && salary == other.salary && hireDay.equals(other.hireDay);
}
}
package abstractClasses;

/**
* Created by xkfx on 2016/12/20.
*/
public class Manager extends Employee{
private double bonus; public Manager(String name){
super(name, 0, 2016, 10, 19);
} public boolean equals(Object otherObject){
// 比较父类实例域是否相等
if(!super.equals(otherObject))
return false;
// 比较子类实例域是否相等
Manager other = (Manager)otherObject;
return this.bonus == other.bonus;
}
}

equals的更多相关文章

  1. equals变量在前面或者在后面有什么区别吗?这是一个坑点

    我就不废话那么多,直接上代码: package sf.com.mainTest; public class Test { public static void main(String[] args) ...

  2. How to implement equals() and hashCode() methods in Java[reproduced]

    Part I:equals() (javadoc) must define an equivalence relation (it must be reflexive, symmetric, and ...

  3. 【特种兵系列】String中的==和equals()

    1. 小样示例 public static void main(String[] args) { String a = "a" + "b" + 123; Str ...

  4. (转)浅谈Java中的equals和==

    原文地址: http://www.cnblogs.com/dolphin0520/p/3592500.html 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new S ...

  5. 浅谈Java中的equals和==(转)

    浅谈Java中的equals和== 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str ...

  6. List<T>Find方法,FindAll方法,Contains方法,Equals方法

    假如传入的T是一个类, List<MessageInfos> MessageInfos = new List<MessageInfos>(); MessageInfos= Me ...

  7. 让代码重构渐行渐远系列(3)——string.Equals取代直接比较与非比较

    重构背景及原因 最近由于项目组的人员在不断扩充,导致项目中代码风格各异,大有百花齐放甚至怒放之势.考虑到团队的生存与发展,经过众人多次舌战之后,最终决定项目组根据业务分成几个小分队,以加强团队管理与提 ...

  8. [java] 更好的书写equals方法-汇率换算器的实现(4)

    [java] 更好的书写equals方法-汇率换算器的实现(4) // */ // ]]>   [java] 更好的书写equals方法-汇率换算器的实现(4) Table of Content ...

  9. Equals和ReferenceEquals

    稍微分析下一下两个方法的区别: public static bool Equals(object objA, object objB); public static bool ReferenceEqu ...

  10. 【原创】Java和C#下String类型中的==和equals的原理与区别

    一.Java下 1.几个例子 public static void main(String[] arge) { String str1 = new String("1234"); ...

随机推荐

  1. jfinal路由简单解析

    在jfinal中,通过JFinalFilter对所有的类进行过滤. 以下是路由的调用关系(我在调用关系旁边做了标记,会贴出具体的代码和解释): -1- Config: Routes -2- Inter ...

  2. 针对focus和blur的Dom事件触发顺序

    Dom事件触发顺序,拿文本框举例: 它会先触发focus事件,之后才会触发在有交点之后才能触发的一些如 click  change 等事件(但如果有mousedown则先执行). 而相对于blur而言 ...

  3. Wordpress制作文章页面single.php

    可以调用的文章内容: 调用文章标题:<?php the_title(); ?> 调用文章内容:<?php the_content(); ?> 调用文章摘要:<?php t ...

  4. LeetCode Graph Valid Tree

    原题链接在这里:https://leetcode.com/problems/graph-valid-tree/ 题目: Given n nodes labeled from 0 to n - 1 an ...

  5. Python开发【第八章】:Socket

    一.Socket socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. so ...

  6. Jmeter多机并发压测IP地址问题

    meter.engine.RemoteJMeterEngineImpl: Local IP address=192.168.56.1 不能成功链家到相应的压力机 解决步骤: 1.找到jmeter.ba ...

  7. JSP和Server的相互转化

    [设计想法] [前置条件] 1. eclipse的web环境已经搭建OK 2. eclipse已经存在web项目"firstweb" [操作步骤] 1. "firstwe ...

  8. 安装vim

    命令安装vim sudo apt-get install vim

  9. <<卸甲笔记>>-基础语法对比

    以Oracle中sottt用户下的数据为例,PPAS 中scott用户下面的数据由Oracle迁移而来 1 查询emp表中的数据 Oracle [root@test03 ~]# su -  oracl ...

  10. android opengl

    引用:http://weimingtom.iteye.com/blog/1616972 二维坐标系变换为原点在左上角(测试用) * GLES * JOGL * LWJGL * libgdx(使用g2d ...