如何用java编程,编写图上的程序?
按照题目要求梁誉编写的Java程序如下
C2.java文件
class PersonB{
String name;
int age;
PersonB(){
System.out.println("无参数的构造方法被调用");
}
PersonB(String name,int age){
this.name=name;
this.age=age;
}
}
class StudentB extends PersonB{
String department;
StudentB(String name,int age,String department){
super(name,age);
this.department=department;
}
void introduce(){
System.out.println("姓名:"+super.name+",年龄:"+super.age+"派饥,部门:"橡羡段+this.department);
}
}
public class C2{
public static void main(String[] args){
StudentB s1=new StudentB("张三",21,"你就读学校的名称");
s1.introduce();
StudentB s2=new StudentB("李四",22,"软件工程");
s2.introduce();
}
}