week5 Inner Class and Anonymous Class
5.5內部類與匿名類
內部類
嵌套類
匿名類
內部類(Inner class):
內部類不與外部類同名
外部對象名.new 內部類
外類類名.this.字段及方法
代碼:TestInnerClass.java與TestInnerThis.java
內部類的修飾符:外部只能用public與默認
Static 修飾符:
實際是外部class
new前面不用對象實例
不能訪問非static
代碼:TestInnerStatic.java
局部類:
在方法建立的類
Code:TestInnerMethod.java
不能用:public, private, protected, static等方式
不能訪問方法的local variable,除非是final
匿名類(anonymous class):
1次性使用
new 類名或接口名,不用extends及implement
不能定義構造方法
Code:SortTest.java
總結:
此章最主要提及內部類(包括嵌套類、局部類),還有匿名類的特性,然後4個code講解(需再次demo+抄寫一遍),此印象深刻的點就是,語法正確,但是邏輯有問題的問題,需要再刻意演練一遍。
Last updated
Was this helpful?