| 
 
| 下面一点简单的代码几乎包涵面向对象70%的知识哦。 
 复制代码class Extends
{
    public static void main(String[] args) 
    {
        new Runner(){
            public void getSum(int a,int b){
                System.out.println(a+b);
            }
        }.getSum(2,3);
        new Pelope(){
            public Pelope shot(){
                System.out.println("喊一声");
                return this;
            }
        }.shot().getSum(1,3);
        
        new SuperPelope().shot().shot().shot().shot()
            .shot().shot().shot().shot().shot().shot()
            .shot().shot().shot().shot().shot().getSum(SuperPelope.count,0);
        //可以一直喊下去。
        //也可以通过for循环控制喊叫次数。。。
        SuperPelope.count=0;
        SuperPelope pe=new SuperPelope();
        for(int i=0;i<20;i++){
            pe=(SuperPelope)pe.shot();
        }
    }
}
interface Runner
{
    void getSum(int a,int b);
}
abstract class Pelope implements Runner{
    public void getSum(int a,int b){
        System.out.println(a+b);
    }
    abstract Pelope shot();
}
class SuperPelope extends Pelope
{
    static int count=0;
    public Pelope shot(){
        System.out.println("喊"+(++count)+"声!");
        return this;
    }
}
 | 
 |