应该是不能同时这样吧
this(变量)//或者super(变量);
你如果这样的话是完全可以的.
[AppleScript] 纯文本查看 复制代码 class Person
{
String name;
Person(String name)
{
this.name=name;
}
public void say()
{
System.out.println(name);
}
}
class Student extends Person
{
int age;
Student(String name,int age)
{
super(name);
this.age=age;
}
public void say()
{
System.out.println(name+" "+age);
}
}
class Demo
{
public static void main(String[] args)
{
Student s=new Student("小明",1);
s.say();
}
} |