public class classTest {
public static void main(String[] args) {
Student stu = new Student("amixuse",25,90);
stu.show();
}
}
class Person {
String name;
int age;
public Person(String name, int age) // 带两个参数的构造方法
{
this(name);
this.age = age;
}
public Person(String name) { // 带一个参数的构造方法
this.name = name;
this.age = 0;
}
public void show() {
System.out.println("姓名为:" + name);
System.out.println("年龄为:" + age);
}
}
class Student extends Person {
private int g;
public Student(String name, int age, int g) {
super(name, age);
this.g = g;
}
public void show() {
System.out.println("姓名为:" + name);
System.out.println("年龄为:" + age);
System.out.println("成绩为:" + g);
}
}
class Test
{
public static void main(String []args)
{
Student stu=new Student(20);
stu.show();
}
}
class Person
{
String name;
int age;
public Person(String name,int age) //带两个参数的构造方法
{
this.name=name;
this.age=age;
}
public Person(String name)
{ //带一个参数的构造方法
this.age=0;
this.name=name;
}
public void show()
{
System.out.println("姓名为:"+name);
System.out.println("年龄为:"+age);
}
}
class Student extends Person{
private int g;
public Student(int g)
{
super("kobe",35);
this.g=g;
}
public void show(){
System.out.println("姓名为:"+name);
System.out.println("年龄为:"+age);
System.out.println("成绩为:"+g);
}
}
还有什么要求的话再说