标题: 一个关于super的问题? [打印本页] 作者: 李平 时间: 2012-4-14 20:16 标题: 一个关于super的问题? class Person
{
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void show(int a)
{
System.out.println(a);
}
}
class Student extends Person
{
String name;
int age;
public Student(String name, int age)
{
super(name, age);
}
public void show(int a)
{
super.show(a);
}
}
class PersonDemo
{
public static void main(String[] args)
{
Student s = new Student("lisi",3);
s.show(1);
}
}
希望能解决你的疑惑。我们一起加油。作者: 黑马-王建雨 时间: 2012-4-14 21:27
class Person
{
String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void show(int a)
{
System.out.println(a);
}
}
class Student extends Person
{
// String name;
// int age;
public Student(String name, int age)
{
super(name, age);
}
/*
public void show(int a)
{
super.show(a);
}
*/
}
class PersonDemo
{
public static void main(String[] args)
{
Student s = new Student("lisi",3);
s.show(1);
}
}作者: 黑马-王建雨 时间: 2012-4-14 21:28
啷个里个郞 发表于 2012-4-14 21:27
class Person
{
String name;