首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

菜鸟java疑难

2013-06-19 
初学者java疑难public class Shape {private String colorpublic Shape(){}public String Shape(String c

初学者java疑难
public class Shape 
{
private String color;
public Shape()
{
}
public String Shape(String color)
{
this.color = color;
}
void show()
{
System.out.println(color);
}
public int getColor()
{
return this.color;
}
}

public class Circle extends Shape
{
private int radius;
public Circle (String color ,int radius)
{
super(color);
this.radius=radius;
}
void show()
{
System.out.println(color,+radius);
}
}

public class Rectangle extends Circle
{
private int a;
private int b;
public Rectangle (String color, int a,int b)
{
super(color);
this.a = a;
this.b = b;
}
void show()
{
System.out.println(getColor(),+a,+b);
}

}
class TestShape
{
public static void main(String[] args) 
{
Rectangle shape1 = new Shape("lanse",2,3);
shape1.show();
}
}

请哪位大神帮帮忙改下或者指点下这个程序,谢谢了
[解决办法]
package com.csdn.test;

class Shape {
    private String color;
    
    public Shape() {
    }
    
    public void setColor(String color) {
        this.color = color;
    }
    
    void show() {
        System.out.println(color);
    }
    
    public String getColor() {
        return this.color;
    }
}

class Circle extends Shape {
    private int radius;
    
    public Circle(String color, int radius) {
        setColor(color);
        this.radius = radius;
    }
    
    @Override
    void show() {
        System.out.println(getColor() + radius);
    }
}

class Rectangle extends Circle {
    private int a;
    
    private int b;

    public Rectangle(String color, int radius) {
        super(color, radius);
    }

    public Rectangle(String color, int a, int b) {


        this(color, 0);
        this.a = a;
        this.b = b;
    }
    
   
    
    @Override
    void show() {
        System.out.println(getColor() + a + b);
    }
    
}

public class TestShape {
    public static void main(String[] args) {
        Shape shape1 = new Rectangle("lanse", 2, 3);
        shape1.show();
    }
}

热点排行