Skip to content

Commit 9de1537

Browse files
committed
auto commit
1 parent 4cfba41 commit 9de1537

File tree

1 file changed

+55
-22
lines changed

1 file changed

+55
-22
lines changed

notes/Java 基础.md

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* [继承](#继承)
1010
* [1. 访问权限](#1-访问权限)
1111
* [2. 抽象类与接口的区别](#2-抽象类与接口的区别)
12-
* [3. super()](#3-super)
12+
* [3. super](#3-super)
1313
* [String](#string)
1414
* [1. String, StringBuffer and StringBuilder](#1-string,-stringbuffer-and-stringbuilder)
1515
* [2. String 不可变的原因](#2-string-不可变的原因)
@@ -114,23 +114,35 @@ public InitialOrderTest() {
114114

115115
## 1. 概览
116116

117-
- public final native Class<?> getClass()
118-
- public native int hashCode()
119-
- public boolean equals(Object obj)
120-
- protected native Object clone() throws CloneNotSupportedException
121-
- public String toString()
122-
- public final native void notify()
123-
- public final native void notifyAll()
124-
- public final native void wait(long timeout) throws InterruptedException
125-
- public final void wait(long timeout, int nanos) throws InterruptedException
126-
- public final void wait() throws InterruptedException
127-
- protected void finalize() throws Throwable { }
117+
```java
118+
public final native Class<?> getClass()
119+
120+
public native int hashCode()
121+
122+
public boolean equals(Object obj)
123+
124+
protected native Object clone() throws CloneNotSupportedException
125+
126+
public String toString()
127+
128+
public final native void notify()
129+
130+
public final native void notifyAll()
131+
132+
public final native void wait(long timeout) throws InterruptedException
133+
134+
public final void wait(long timeout, int nanos) throws InterruptedException
135+
136+
public final void wait() throws InterruptedException
137+
138+
protected void finalize() throws Throwable {}
139+
```
128140

129141
## 2. clone()
130142

131143
**浅拷贝**
132144

133-
引用类型引用的是同一个对象,clone() 方法默认就是浅拷贝实现。
145+
引用类型引用同一个对象。clone() 方法默认就是浅拷贝实现。
134146

135147
<div align="center"> <img src="../pics//d990c0e7-64d1-4ba3-8356-111bc91e53c5.png"/> </div><br>
136148

@@ -147,19 +159,19 @@ public InitialOrderTest() {
147159
- 对于基本类型,== 就是判断两个值是否相等;
148160
- 对于引用类型,== 是判断两个引用是否引用同一个对象,而 equals() 是判断引用的对象是否等价。
149161

150-
等价性:[ 散列 ](https://github.com/CyC2018/InterviewNotes/blob/master/notes/Java%20%E5%AE%B9%E5%99%A8.md#%E6%95%A3%E5%88%97)
162+
等价性:[散列](https://github.com/CyC2018/Interview-Notebook/blob/master/notes/Java%20%E5%AE%B9%E5%99%A8.md#%E6%95%A3%E5%88%97)
151163

152164
# 继承
153165

154166
## 1. 访问权限
155167

156168
Java 中有三个访问权限修饰符:private、protected 以及 public,如果不加访问修饰符,表示包级可见。
157169

158-
可以对类或类中的成员(字段以及方法)加上访问修饰符。成员可见表示其它类可以用成员所在类的对象访问到该成员;类可见表示其它类可以用这个类创建对象,可以把类当做包中的一个成员,然后包表示一个类,这样就好理解了
170+
可以对类或类中的成员(字段以及方法)加上访问修饰符。成员可见表示其它类可以用成员所在类的对象访问到该成员;类可见表示其它类可以用这个类创建对象。在理解类的可见性时,可以把类当做包中的一个成员,然后包表示一个类,那么就可以类比成员的可见性
159171

160172
protected 用于修饰成员,表示在继承体系中成员对于子类可见。但是这个访问修饰符对于类没有意义,因为包没有继承体系。
161173

162-
更详细的内容:[ 浅析 Java 中的访问权限控制 ](http://www.importnew.com/18097.html)
174+
更详细的内容:[浅析 Java 中的访问权限控制](http://www.importnew.com/18097.html)
163175

164176
## 2. 抽象类与接口的区别
165177

@@ -177,7 +189,7 @@ public abstract class GenericServlet implements Servlet, ServletConfig, Serializ
177189
}
178190
```
179191

180-
接口定义了一组方法,但是接口都没有方法的实现,也就是说这些方法都是抽象方法
192+
接口定义了一组方法,但是接口都没有方法的实现,可以理解为这些方法都是抽象方法
181193

182194
```java
183195
public interface Externalizable extends Serializable {
@@ -188,26 +200,47 @@ public interface Externalizable extends Serializable {
188200
}
189201
```
190202

191-
更详细的内容:[Java 抽象类与接口的区别 ](http://www.importnew.com/12399.html)
203+
更详细的内容:[Java 抽象类与接口的区别](http://www.importnew.com/12399.html)
192204

193-
## 3. super()
205+
## 3. super
194206

195-
用来访问父类的构造函数父类的方法,第二种情况中,子类需要重载父类的方法。
207+
**访问父类的成员**
208+
209+
如果子类覆盖了父类的中某个方法的实现,那么就可以通过使用 super 关键字来引用父类的方法实现。
210+
211+
```java
212+
public class Superclass {
213+
public void printMethod() {
214+
System.out.println("Printed in Superclass.");
215+
}
216+
}
217+
```
196218

197219
```java
198220
public class Subclass extends Superclass {
199-
// overrides printMethod in Superclass
221+
// Overrides printMethod in Superclass
200222
public void printMethod() {
201223
super.printMethod();
202224
System.out.println("Printed in Subclass");
203225
}
204226
public static void main(String[] args) {
205227
Subclass s = new Subclass();
206-
s.printMethod();
228+
s.printMethod();
207229
}
208230
}
209231
```
210232

233+
**访问父类的构造函数**
234+
235+
可以使用 super() 函数访问父类的构造函数,从而完成一些初始化的工作。
236+
237+
```java
238+
public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
239+
super(startCadence, startSpeed, startGear);
240+
seatHeight = startHeight;
241+
}
242+
```
243+
211244
> [Using the Keyword super](https://docs.oracle.com/javase/tutorial/java/IandI/super.html)
212245

213246
# String

0 commit comments

Comments
 (0)