初学者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) {