用java继承编写3个类,要求看下图
发布网友
发布时间:2022-04-23 21:17
我来回答
共2个回答
热心网友
时间:2023-10-09 22:06
我将程序分为了两个文件,一个文件存放Student类、Freshman类(大一学生)和,Sophomore类(大二学生),另一个类存放主调程序类Exos11,具体代码如下所示,首先是学生类:
class Student
{
public String name;
Student(String name)
{
this.name = name;
}
public void learnMarxism()
{
System.out.println(this.name + " learn Marxism");
}
}
class Freshman extends Student
{
Freshman(String name)
{
super(name);
}
public void learnJavaSE()
{
System.out.println(this.name + " learn JavaSE");
}
}
class Sophomore extends Student
{
Sophomore(String name)
{
super(name);
}
public void learnJavaEE()
{
System.out.println(this.name + " learn JavaEE");
}
}
然后是主调程序类:
public class Exos11
{
public void printInfo()
{
Freshman fr = new Freshman("Jack");
Sophomore so = new Sophomore("Jane");
fr.learnMarxism();
so.learnMarxism();
fr.learnJavaSE();
so.learnJavaEE();
}
public static void main(String[] args)
{
Exos11 ex = new Exos11();
ex.printInfo();
}
}
以上就是我的答案,如有问题,欢迎追问。
热心网友
时间:2023-10-09 22:06
可以帮忙写