A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Peng苏 中级黑马   /  2015-3-17 23:38  /  592 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

根据下面代码,,判断控制台输出的是????
class Guees
{
        //定义属性并私有性
        private static int nextId;
        private int id = assignId();//调有assignId方法来为ID赋值
        private static int assignId()
        {       
                int r = nextId;
                nextId++;
                return r;
        }
        void show()
        {
                System.out.println(id);
        }
}
class Test
{
        public static void main(String[] args)
        {
               
                Guees num= new Guees();
                Guees num1= new Guees();
                Guees num2= new Guees();
                new Guees().show();
                num.show();
                num2.show();
                num.show();
                num1.show();
        }

}1 0 2 0 3

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马