王吉元-NWPU

导航

 
package com.wjy.effective;

public enum Singleton {
    INSTANCE;
    
    private int numa;
    private int numb;
    public int add(int a,int b){
        numa=a;
        numb=b;
        return numa+numb;
    }
}

 

客户端代码:

package com.wjy.effective;

public class TestSingleton {
    public static void main(String args[]){
        Singleton instance=Singleton.INSTANCE;
        int sum=instance.add(6, 7);

        System.out.println("result is: "+(sum+1));
    }
}

 

运行结果:

result is: 14

 

posted on 2013-12-18 22:27  王吉元  阅读(213)  评论(0编辑  收藏  举报