一道Java的题,请高手解答
该题是:定义一个抽象类AbstractTest,其中有一个公共的抽象方法dispMessage()。然后定义此抽象类的一个子集StudentTest,子类中包含姓名、学好...
该题是:定义一个抽象类AbstractTest,其中有一个公共的抽象方法dispMessage()。然后定义此抽象类的一个子集StudentTest,子类中包含姓名、学好及分数三个属性,子类具有两个构造方法。
为上面的问题编写程序 展开
为上面的问题编写程序 展开
3个回答
展开全部
//抽象类AbstractTest
package help;
public abstract class AbstractTest {
abstract void dispTest();
}
//子类:StudentTest
package help;
public class StudentTest {
private String name;
private int num;
private int score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public StudentTest() {
}
public StudentTest(String name, int num, int score) {
this.name = name;
this.num = num;
this.score = score;
}
public void dispTest() {
StudentTest st = new StudentTest(name, num, score);
String name = st.getName();
int num = st.getNum();
int score = st.getScore();
System.out.println("姓名:" + name + "\n" + "学号:" + num + "\n" + "分数:"+ score);
}
public static void main(String[] args) {
StudentTest st = new StudentTest("科比", 24, 81);
st.dispTest();
}
}
package help;
public abstract class AbstractTest {
abstract void dispTest();
}
//子类:StudentTest
package help;
public class StudentTest {
private String name;
private int num;
private int score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public StudentTest() {
}
public StudentTest(String name, int num, int score) {
this.name = name;
this.num = num;
this.score = score;
}
public void dispTest() {
StudentTest st = new StudentTest(name, num, score);
String name = st.getName();
int num = st.getNum();
int score = st.getScore();
System.out.println("姓名:" + name + "\n" + "学号:" + num + "\n" + "分数:"+ score);
}
public static void main(String[] args) {
StudentTest st = new StudentTest("科比", 24, 81);
st.dispTest();
}
}
展开全部
public abstract class AbstractTest {
public abstract void dispMessage();
}
public class StudentTest extends AbstractTest {
public String name;
public String id;
public Integer score;
public StudentTest(){
}
public StudentTest(String name,String id,Integer score){
this.name=name;
this.id=id;
this.score=score;
}
public void dispMessage() {
}
}
public abstract void dispMessage();
}
public class StudentTest extends AbstractTest {
public String name;
public String id;
public Integer score;
public StudentTest(){
}
public StudentTest(String name,String id,Integer score){
this.name=name;
this.id=id;
this.score=score;
}
public void dispMessage() {
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public abstract class AbstractTest {
abstract void dispMessage();
}
public abstract class AbstractTest {
abstract void dispMessage();
}
abstract void dispMessage();
}
public abstract class AbstractTest {
abstract void dispMessage();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询