本帖最后由 黄长利 于 2012-3-28 22:46 编辑
- class Demo
- {
- public static void main(String[] args)
- {
- Student stu = new Student("小黑"); //主函数是静态的,调用所属类中的内部成员时,成员也必须是静态的
- System.out.println(stu.name);
- }
- static class Person
- {
- String name;
- Person(String name)
- {
- this.name = name;
- }
- void show()
- {
- System.out.println("father's name :"+name);
- }
- }
- static class Student extends Person //此处添加 static ,由于此类中有父类引用,将父类也添加static即可
- {
- Student(String name)
- {
- super(name);
- }
- void method()
- {
- super.show();
- }
- }
- }
复制代码 |