auto commit
This commit is contained in:
parent
4cfba41ab0
commit
9de1537dbb
@ -9,7 +9,7 @@
|
|||||||
* [继承](#继承)
|
* [继承](#继承)
|
||||||
* [1. 访问权限](#1-访问权限)
|
* [1. 访问权限](#1-访问权限)
|
||||||
* [2. 抽象类与接口的区别](#2-抽象类与接口的区别)
|
* [2. 抽象类与接口的区别](#2-抽象类与接口的区别)
|
||||||
* [3. super()](#3-super)
|
* [3. super](#3-super)
|
||||||
* [String](#string)
|
* [String](#string)
|
||||||
* [1. String, StringBuffer and StringBuilder](#1-string,-stringbuffer-and-stringbuilder)
|
* [1. String, StringBuffer and StringBuilder](#1-string,-stringbuffer-and-stringbuilder)
|
||||||
* [2. String 不可变的原因](#2-string-不可变的原因)
|
* [2. String 不可变的原因](#2-string-不可变的原因)
|
||||||
@ -114,23 +114,35 @@ public InitialOrderTest() {
|
|||||||
|
|
||||||
## 1. 概览
|
## 1. 概览
|
||||||
|
|
||||||
- public final native Class<?> getClass()
|
```java
|
||||||
- public native int hashCode()
|
public final native Class<?> getClass()
|
||||||
- public boolean equals(Object obj)
|
|
||||||
- protected native Object clone() throws CloneNotSupportedException
|
public native int hashCode()
|
||||||
- public String toString()
|
|
||||||
- public final native void notify()
|
public boolean equals(Object obj)
|
||||||
- public final native void notifyAll()
|
|
||||||
- public final native void wait(long timeout) throws InterruptedException
|
protected native Object clone() throws CloneNotSupportedException
|
||||||
- public final void wait(long timeout, int nanos) throws InterruptedException
|
|
||||||
- public final void wait() throws InterruptedException
|
public String toString()
|
||||||
- protected void finalize() throws Throwable { }
|
|
||||||
|
public final native void notify()
|
||||||
|
|
||||||
|
public final native void notifyAll()
|
||||||
|
|
||||||
|
public final native void wait(long timeout) throws InterruptedException
|
||||||
|
|
||||||
|
public final void wait(long timeout, int nanos) throws InterruptedException
|
||||||
|
|
||||||
|
public final void wait() throws InterruptedException
|
||||||
|
|
||||||
|
protected void finalize() throws Throwable {}
|
||||||
|
```
|
||||||
|
|
||||||
## 2. clone()
|
## 2. clone()
|
||||||
|
|
||||||
**浅拷贝**
|
**浅拷贝**
|
||||||
|
|
||||||
引用类型引用的是同一个对象,clone() 方法默认就是浅拷贝实现。
|
引用类型引用同一个对象。clone() 方法默认就是浅拷贝实现。
|
||||||
|
|
||||||
<div align="center"> <img src="../pics//d990c0e7-64d1-4ba3-8356-111bc91e53c5.png"/> </div><br>
|
<div align="center"> <img src="../pics//d990c0e7-64d1-4ba3-8356-111bc91e53c5.png"/> </div><br>
|
||||||
|
|
||||||
@ -147,7 +159,7 @@ public InitialOrderTest() {
|
|||||||
- 对于基本类型,== 就是判断两个值是否相等;
|
- 对于基本类型,== 就是判断两个值是否相等;
|
||||||
- 对于引用类型,== 是判断两个引用是否引用同一个对象,而 equals() 是判断引用的对象是否等价。
|
- 对于引用类型,== 是判断两个引用是否引用同一个对象,而 equals() 是判断引用的对象是否等价。
|
||||||
|
|
||||||
等价性:[ 散列 ](https://github.com/CyC2018/InterviewNotes/blob/master/notes/Java%20%E5%AE%B9%E5%99%A8.md#%E6%95%A3%E5%88%97)
|
等价性:[散列](https://github.com/CyC2018/Interview-Notebook/blob/master/notes/Java%20%E5%AE%B9%E5%99%A8.md#%E6%95%A3%E5%88%97)
|
||||||
|
|
||||||
# 继承
|
# 继承
|
||||||
|
|
||||||
@ -155,7 +167,7 @@ public InitialOrderTest() {
|
|||||||
|
|
||||||
Java 中有三个访问权限修饰符:private、protected 以及 public,如果不加访问修饰符,表示包级可见。
|
Java 中有三个访问权限修饰符:private、protected 以及 public,如果不加访问修饰符,表示包级可见。
|
||||||
|
|
||||||
可以对类或类中的成员(字段以及方法)加上访问修饰符。成员可见表示其它类可以用成员所在类的对象访问到该成员;类可见表示其它类可以用这个类创建对象,可以把类当做包中的一个成员,然后包表示一个类,这样就好理解了。
|
可以对类或类中的成员(字段以及方法)加上访问修饰符。成员可见表示其它类可以用成员所在类的对象访问到该成员;类可见表示其它类可以用这个类创建对象。在理解类的可见性时,可以把类当做包中的一个成员,然后包表示一个类,那么就可以类比成员的可见性。
|
||||||
|
|
||||||
protected 用于修饰成员,表示在继承体系中成员对于子类可见。但是这个访问修饰符对于类没有意义,因为包没有继承体系。
|
protected 用于修饰成员,表示在继承体系中成员对于子类可见。但是这个访问修饰符对于类没有意义,因为包没有继承体系。
|
||||||
|
|
||||||
@ -177,7 +189,7 @@ public abstract class GenericServlet implements Servlet, ServletConfig, Serializ
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
接口定义了一组方法,但是接口都没有方法的实现,也就是说这些方法都是抽象方法。
|
接口定义了一组方法,但是接口都没有方法的实现,可以理解为这些方法都是抽象方法。
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public interface Externalizable extends Serializable {
|
public interface Externalizable extends Serializable {
|
||||||
@ -190,13 +202,23 @@ public interface Externalizable extends Serializable {
|
|||||||
|
|
||||||
更详细的内容:[Java 抽象类与接口的区别](http://www.importnew.com/12399.html)
|
更详细的内容:[Java 抽象类与接口的区别](http://www.importnew.com/12399.html)
|
||||||
|
|
||||||
## 3. super()
|
## 3. super
|
||||||
|
|
||||||
用来访问父类的构造函数父类的方法,第二种情况中,子类需要重载父类的方法。
|
**访问父类的成员**
|
||||||
|
|
||||||
|
如果子类覆盖了父类的中某个方法的实现,那么就可以通过使用 super 关键字来引用父类的方法实现。
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Superclass {
|
||||||
|
public void printMethod() {
|
||||||
|
System.out.println("Printed in Superclass.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class Subclass extends Superclass {
|
public class Subclass extends Superclass {
|
||||||
// overrides printMethod in Superclass
|
// Overrides printMethod in Superclass
|
||||||
public void printMethod() {
|
public void printMethod() {
|
||||||
super.printMethod();
|
super.printMethod();
|
||||||
System.out.println("Printed in Subclass");
|
System.out.println("Printed in Subclass");
|
||||||
@ -208,6 +230,17 @@ public class Subclass extends Superclass {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**访问父类的构造函数**
|
||||||
|
|
||||||
|
可以使用 super() 函数访问父类的构造函数,从而完成一些初始化的工作。
|
||||||
|
|
||||||
|
```java
|
||||||
|
public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
|
||||||
|
super(startCadence, startSpeed, startGear);
|
||||||
|
seatHeight = startHeight;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
> [Using the Keyword super](https://docs.oracle.com/javase/tutorial/java/IandI/super.html)
|
> [Using the Keyword super](https://docs.oracle.com/javase/tutorial/java/IandI/super.html)
|
||||||
|
|
||||||
# String
|
# String
|
||||||
|
Loading…
x
Reference in New Issue
Block a user