admin 管理员组文章数量: 887021
考试题
目录
一、程序运行截图
二、代码
一、程序运行截图
二、代码
class Student {protected double height;protected double weight;public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public double getWeight() {return weight;}public void setWeight(double weight) {this.weight = weight;}public void speakHello() {System.out.println("hello!");}public void averageHeight() {System.out.println("avarge heigh:" + height);}public void averageWeight() {System.out.println("average weight:" + weight);}
}class LiberalArtsStudent extends Student {public void speakHello() {System.out.println("hello,I am liberal arts student!");
}public void averageHeight() {System.out.println("avarge heigh of LiberalArtsStudent:" + height);
}public void averageWeight() {System.out.println("average weight of LiberalArtsStudent:" + weight);
}public void liberalArtsFeature(){System.out.println("I read history.");}
}
class ScienceStudent extends Student {public void speakHello() {System.out.println("hello,I am science student.");
}public void averageHeight() {System.out.println("avarge heigh of ScienceStudent:" + height);
}public void averageWeight() {System.out.println("average weight of ScienceStudent:" + weight);
}public void scienceFeature(){System.out.println("I do experiment.");}
}
public class TestStudent {public static void main(String[] args) {ScienceStudent chp = new ScienceStudent();chp.height = 180;chp.weight = 130;chp.speakHello();chp.averageHeight();chp.averageWeight();chp.scienceFeature();LiberalArtsStudent amp = new LiberalArtsStudent();amp.setHeight(175);amp.setWeight(150);amp.speakHello();amp.averageHeight();amp.averageWeight();amp.liberalArtsFeature();
}
}
本文标签: 考试题
版权声明:本文标题:考试题 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1699318860h342338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论