core JAVA for the impatient 阅读笔记(3) 继承

继承一个类

  • 实例变量和动态变量称为,类中的域,方法和嵌套类/接口统称为类成员
  • 反射机制:一种在程序运行期间查找类及其成员的能力
 return **super.**getSalary()+bonus;
  • 因为Manager类的构造函数,不能访问Employee类的私有变量,所以他必须通过父类的构造函数来初始化他们。父类构造函数的调用必须是子类构造函数的第一条语句。
 public Manager(String name,double salary){
 	super(name,salary);
 	bonus = 0;
 }
  • 不同于接口,抽象类可以拥有实例变量和构造函数。构造抽象类的实例是不可能的,但是你可以拥有一个类型为抽象类的变量,前提是该变量引用一个具体的子类的对象。
public class Student extends Person{
	private int id;
	public Student(String name,int id){ super(name);this.id=id;}
	public int getId{return id;}
}

Person p = new Student("April",1996);//OK,student是具体的子类

Object:终极父类

  • hashcode和equals方法必须是兼容的
  • 克隆对象
  1. 浅拷贝 object.clone
    他简单的从源对象中拷贝所有实例变量到被拷贝对象里,如果实力变量都是基本类型或者不会改变,那没问题,但是如果他们不是原对象和克隆对象,将共享可变的状态,这会有问题。
  2. 深拷贝
    例如有列表变量等,改变其一另一个也会被改变
  • 一般情况下,当你需要实现一个类,使你要考虑如下情况,是否提供克隆方法。如果不提供克隆方法,那么继承自父类的克隆方法是否可以接受,如果继承自父类的克隆方法不可接受。就需要提供实现深拷贝的克隆方法。
  • 如果需要深拷贝,你的类必须实现cloneable接口,这是一个没有任何方法的接口,称作标签接口。克隆方法执行浅拷贝之前会检查这个接口是否被实现,如果没有会抛出异常。
The release of Java SE 8 introduced significant enhancements that impact the Core Java technologies and APIs at the heart of the Java platform. Many old Java idioms are no longer required and new features like lambda expressions will increase programmer productivity, but navigating these changes can be challenging., , Core Java® for the Impatient is a complete but concise guide to Java SE 8. Written by Cay Horstmann—the author of Java SE 8 for the Really Impatient and Core Java™, the classic, two-volume introduction to the Java language—this indispensable new tutorial offers a faster, easier pathway for learning the language and libraries. Given the size of the language and the scope of the new features introduced in Java SE 8, there’s plenty of material to cover, but it’s presented in small chunks organized for quick access and easy understanding., , If you’re an experienced programmer, Horstmann’s practical insights and sample code will help you quickly take advantage of lambda expressions (closures), streams, and other Java language and platform improvements. Horstmann covers everything developers need to know about modern Java, including, - Crisp and effective coverage of lambda expressions, enabling you to express actions with a concise syntax, - A thorough introduction to the new streams API, which makes working with data far more flexible and efficient, - A treatment of concurrent programming that encourages you to design your programs in terms of cooperating tasks instead of low-level threads and locks, - Up-to-date coverage of new libraries like Date and Time, - Other new features that will be especially valuable for server-side or mobile programmers, Whether you are just getting started with modern Java or are an experienced developer, this guide will be invaluable for anyone who wants to write tomorrow’s most robust, efficient, and secure Java code.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值