TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
- [code]package test10;
- //无论内部类是公开还是私有都不能被继承,因为它不是属性,也不是方法。而是一个内部事务的描述。
- public class Demo {
- public static void main(String[] args) {
- Pm p=new Pm(){//匿名内部类必须实现一个接口或者继承一个类,必须重写接口和类中的抽象方法
- public void show() {
- }
- void fly(){
- }
- };
- System.out.println(p.a);//引用能调用什么,要看引用类型里面有什么
- p.show();
- // p.fly();编译错误
- Foo.Aoo FA=new Foo().new Aoo();//实例化成员内部类
- FA.show();//调用成员内部类的方法
- Pm.Inner PI=new Pm.Inner();//实例化接口内部类
- Foo ff=new Foo();
- ff.cop();
- }
- }
- interface Pm {//接口
- final int a=9;
- void show();
- class Inner {//接口内部类--默认是public static
- }
- }
- class Foo {//外部类
- private int a;
- void cop(){
- int A=3;
- class Boo {//方法内部类--也可以直接访问外部类的成员变量和方法
- void kk(){}
- void shoe() {
- a=9;//可以写成Foo.this.a=0;
- cop();
- System.out.println(A);//方法内部类能访问被final局部变量,
- kk();
- }
- }
- }
- class Aoo {//成员内部类--可以直接访问外部类的成员变量和方法
- void show() {
- a=0;//可以写成Foo.this.a=0;
- cop();//可以写成Foo.this.cop();
- }
- }
- static class Coo {
- void sh() {
- // cop();//不能访问外部类的非静态变量
- }
- }
- }
复制代码 [/code] $(function () { $("pre.prettyprint code").each(function () { var lines = $(this).text().split("\n").length; var $numbering = $("").addClass("pre-numbering").hide(); $(this).addClass("has-numbering").parent().append($numbering); for (i = 1; i ").text(i)); }; $numbering.fadeIn(1700); }); }); |
|