读书人

菜鸟java疑难

发布时间: 2013-06-19 10:26:41 作者: rapoo

初学者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();
}
}

读书人网 >Java相关

热点推荐