黑马程序员技术交流社区

标题: 为什么不能在成员变量中先定义,再赋值???? [打印本页]

作者: HeiMaZ    时间: 2016-5-6 22:35
标题: 为什么不能在成员变量中先定义,再赋值????
class Demo_Student{
        public static void main(String[] args) {
                Student s = new Student();
                s.name="张三";
                s.age=23;
                s.gender="男";
                s.say();
        }
}

class Student{
        String name;
        int age;
        age=10;
        String gender;
        public void say(){
                System.out.println(name+"\t"+gender+"\t"+age);
        }
}
作者: zlf1991312    时间: 2016-5-7 22:51
这里只能定义成员变量和成员方法
作者: SilentMax    时间: 2016-5-8 00:10
还没有学到,但是提前了解了一下




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