- class Person
- {
- String name ;
- int age;
- Person(String name,int age){
- this.name = name;
- this.age = age;
- }
- public String getName(){
- return name;
- }
- }
- class Test8
- {
- public static void main(String[] args)
- {
- System.out.println(new Person("zhangsan",15).getName());
- //应该没有什么区别吧,无论是否复习方法,都会输出姓名的!
- System.out.println(new Person("zhangsan",15){
-
- public String getName(){
- // return name;
- return super.getName();
- }
- }.getName());
- }
- }
复制代码 |