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

© Moonboy2014 中级黑马   /  2014-6-29 22:31  /  1262 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

interface Person
{
        abstract void show();
}

class Student implements Person
{
        public void show()
        {
                System.out.println("student run");
        }
}

class ProxyStudent implements Person
{
        private Student s;
        public void show()
        {
                before();
                if(s == null)//这个比较是什么意思,为什么不直接new一个Student对象呢?
                {
                        s = new Student();
                }
                s.show();
                after();
        }
        public void before()
        {
                System.out.println("do something before show");
        }
        public void after()
        {
                System.out.println("do something after show");
        }
}
public class ProxyDemo {

        public static void main(String[] args) {
                // TODO Auto-generated method stub
                        ProxyStudent ps = new ProxyStudent();
                        ps.show();
        }

}
请教各位高手,s==null是说明意思,为什么改成s!=null 就提示空指针异常了,知道的详细解答一下,不胜感激

0 个回复

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