public class JIhe {
private String color;
private String dateCreated;
private String filled;
public String getColor() {
return color;
}
public String getDateCreated() {
return dateCreated;
public String getFilled() {
return filled;
public void setColor(String color) {
this.color = color;
public void setFilled(String filled) {
this.filled = filled;
@Override
public String toString() {
return "Color:" + this.color +" filled:" + this.filled + "detaCreated:" + dateCreated;
------------------------------------------------------------------------------------------------------------
public class Circle extends JIhe {
private double radius;
public double getRadius() {
return radius;
public void setRadius(double radius) {
this.radius = radius;
public double getArea() {
public double getPerimeter() {
public double getDiameter() {
-----------------------------------------------------------------------------------------------------
public class Rectangle extends JIhe {
private double width;
private double height;
public double getWidth() {
return width;
public void setWidth(double width) {
this.width = width;
public double getHeight() {
return height;
public void setHeight(double height) {
this.height = height;
public double getArea(){
return this.width * this.height;
public double getPerimeter(){
——————————————————————————————————————
public class Test {
public static void main(String[] args){
Circle circle = new Circle();
circle.setRadius(1.0);
System.out.println(circle.getArea());
System.out.println(circle.getColor());
System.out.println(circle.getDateCreated());
System.out.println(circle.getDiameter());
System.out.println(circle.getFilled());
System.out.println(circle.getPerimeter());
System.out.println(circle.getRadius());
Rectangle r = new Rectangle();
System.out.println(r.getArea());
System.out.println(r.getColor());
System.out.println(r.getDateCreated());
System.out.println(r.getFilled());
System.out.println(r.getHeight());
System.out.println(r.getPerimeter());
System.out.println(r.getWidth());
E.要求:
(1) Monkey类中有个构造方法:Monkey (String s),并且有个public void speak()
方法,在speak方法中输出"咿咿呀呀......"的信息.
中输出"小样的,不错嘛!会说话了!"的信息.
的信息.
能.、
复制代码
package zhongqiuzuoye;
public class Monkey {
Monkey(String s) //构造
{}
public void speak()
{
System.out.println("咿咿呀呀......");
可运行的:
import java.awt.*;
import java.awt.event.*;
public class BackJFrame extends Frame{
public BackJFrame(){
super("台球");
setBackground(Color.cyan); //背景
setVisible(true);
addWindowListener(new WindowAdapter()
public void windowClosing (WindowEvent e)
{System.exit(0);}
} );
public static void main(String args[]){
new BackJFrame();
第一个:
public?class?Yaojing?{
protected?String?name;
protected?int?age;
protected?String?gender;
public?void?showBasicInfo()?{
System.out.println(toString());
public?void?eatTangSeng()?{
System.out.println("吃饱了");
public?String?toString()?{
return?"Yaojing?[name="?+?name?+?",?age="?+?age?+?",?gender="?+?gender?+?"]";
第二个类
public?class?Zhizhujing?extends?Yaojing?{
public?void?buildNet(){
System.out.println("蜘蛛在织网");
第三个类
public?class?Baigujing?extends?Yaojing?{
public?void?beBeauty(){
System.out.println("白骨精");
package?extend;
/**
*?圆类
*/
public?class?Circle?{
private?double?r;
public?Circle(double?r)?{
this.r?=?r;
public?double?Circumference(double?r)?{
public?double?Area(double?r)?{
return?PI*r*r;
*?圆柱类,继承自圆类
public?class?Cylinder?extends?Circle{
private?double?h;
public?Cylinder(double?r,?double?h)?{
super(r);
this.h?=?h;
public?double?CeArea(double?r,?double?h)?{
return?super.Circumference(r)*h;
public?double?Volume(double?r,?double?h)?{
return?super.Area(r)*h;
*?圆锥类,继承自圆柱类
public?class?Cone?extends?Cylinder{
public?Cone(double?r,?double?h)?{
super(r,?h);
*?测试类
public?class?Test?{
public?static?void?main(String[]?args)?{
Circle?circle?=?new?Circle(r);
System.out.println("半径为:"?+?r?+?"?圆的周长为:"?+?circle.Circumference(r));
System.out.println("半径为:"?+?r?+?"?圆的面积为:"?+?circle.Area(r));
System.out.println("底部半径为:"?+?r?+?",高为:"?+?h?+?"?圆柱的侧面积为:"?+?cylinder.CeArea(r,?h));
System.out.println("底部半径为:"?+?r?+?",高为:"?+?h?+?"?圆柱的体积为:"?+?cylinder.Volume(r,?h));
System.out.println("底部半径为:"?+?r?+?",高为:"?+?h?+?"?圆锥的侧面积为:"?+?cone.CeArea(r,?h));
System.out.println("底部半径为:"?+?r?+?",高为:"?+?h?+?"?圆锥的体积为:"?+?cone.Volume(r,?h));
以上就是土嘎嘎小编为大家整理的java继承的程序代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!