public class Demo {
public static void main(String[] args) {
Person p = new Person( "小明", 12) ;
Student s = new Student ("小红", 18, 78.5) ;
}
}
class Person{
String name;
int age;
public Person(String name, int age) {
this.name= name;
this.age =age;
补代码
再加个子类就好了,希望采纳谢谢
class Student extends Person {
double weight;
public Student(String name,int age,double weight){
super(name,age);
this.weight = weight;
}
}
假设Student类是Person类的子类,
class Student extends Person {
double score;
public Student(String name, int age, double score) {
super(name, age);
this.score = score;
}
}
完整代码:
```java
public class Demo {
public static void main(String[] args) {
Person p = new Person("小明", 12);
Student s = new Student("小红", 18, 78.5);
}
}
class Person {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
class Student extends Person {
double score;
public Student(String name, int age, double score) {
super(name, age);
this.score = score;
}
}
```