- 除了构造方法之外的所有属性继承,但也不见得能直接使用。
- 类的结构视图:alt+7
- 类的源码:ctrl+左键
- 查看类的关系 鼠标放到类名上,右键 Diagram show Diagram
- 自动生成构造器、get、set、equal等方法:alt+insert
-
package com.zy.inherit; import java.util.Objects; public class User { int id; String pwd; String name; User(int id,String name,String pwd){ this.id = id; this.name = name; this.pwd = pwd; } @Override public boolean equals(Object o) { if (this == o) return true; //return 返回值,结束运行 if (o == null || getClass() != o.getClass()) return false; User user = (User) o; return id == user.id; } @Override public int hashCode() { return Objects.hash(id); } public static void main(String[] args) { User u1 = new User(1001,"张三","123456"); User u2 = new User(1001,"张三","123456"); System.out.println(u1); System.out.println(u2.toString()); System.out.println(u1==u2);//判断两个对象是不是一样 System.out.println(u1.equals(u2));//判断两个对象逻辑上的值是不是一样 } }