黑马程序员技术交流社区

标题: 静态 [打印本页]

作者: hutudan1993    时间: 2015-8-29 22:03
标题: 静态
class Demo3_Static {
        public static void main(String[] args) {
                //method();                                                                //错误: 无法从静态上下文中引用非静态 方法 method()
                Demo3_Static.print();                                        //在主方法中调用本类的静态方法,可以省略类名.,系统会默认加上
                Demo3_Static d = new Demo3_Static();        //非静态方法在调用的时候必须创建对象调用
                d.method();
        }

        public void method() {                                       
                System.out.println("Hello World!");               
        }

        public static void print() {
                System.out.println("Hello World!");
        }
}
作者: 王小吉    时间: 2015-8-29 22:11
整理的不错 好好学习 加油
作者: jeska    时间: 2015-8-29 22:27
不错,继续努力




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2