package netconnection;/**
 *
 * @author Administrator
 */
public class NetConnection {    /**
     * @param args the command line arguments
     */
    private final static int MAX_CONNECTION_NUM=10;
    private static int connectionNum=0;
    private NetConnection(){
        connectionNum++;
         connectionNum++;
          connectionNum++;
    }
    public static NetConnection getNetConnection(){
        if(connectionNum>=MAX_CONNECTION_NUM) {
            return null;
        }
        else {
            return new NetConnection();
        }
    }
    public void release(){
        connectionNum--;
    }
    public static void main(String[] args) {
        // TODO code application logic 
        Netconnection NC=new Netconnection();       
        System.out.println("connectionNum"+NC.connectionNum);     
        
    }
}
错误就出现在最后一行程序的NC.connectionNum,不知道要改成什么哈?要怎么改,程序才能运行呢?

解决方案 »

  1.   

    改大小写就行了,Java是大小写敏感的:
    NetConnection NC=new NetConnection();
      

  2.   

    谢谢你了!但最后一行代码还是出错哈!怎么输出NetConnection类中的静态变量connectionNum呢?
      

  3.   

    解决了!/*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package netconnection;/**
     *
     * @author Administrator
     */
    public class NetConnection {    /**
         * @param args the command line arguments
         */
        private final static int MAX_CONNECTION_NUM=10;
        private static int connectionNum=0;
        private NetConnection(){
            connectionNum++;
             connectionNum++;
              connectionNum++;
        }
        public static NetConnection getNetConnection(){
            if(connectionNum>=MAX_CONNECTION_NUM) {
                return null;
            }
            else {
                return new NetConnection();
            }
        }
        public void release(){
            connectionNum--;
        }
        public static void main(String[] args) {
            // TODO code application logic 
            NetConnection NC=new NetConnection();       
            System.out.println("connectionNum"+NetConnection.connectionNum);     
            
        }
    }
    正确的代码!!!