我有超类,看起来像:
public abstract class Fish {
protected int size;
protected float weight;
//constructor
public Fish(int s, float w) {
size = aSize;weight = aWeight;}
Run Code Online (Sandbox Code Playgroud)
我有这个超类的2个子类.第一:
public class SomeFish extends Fish{
//constructor
public SomeFish(int s, float w) {
super(s, w) }
Run Code Online (Sandbox Code Playgroud)
第二个:
public class AnotherFish extends Fish{
//constructor
public AnotherFish(int s, float w) {
super(s, w) }
Run Code Online (Sandbox Code Playgroud)
我要做的是在Fish类中编写一个String toString方法,返回类似于:12 cm 0.5 这里应该是适当类型的鱼(AnotherFish或SomeFish).我可以不使用字符串toString方法抽象并在SomeFish和AnotherFish类中实现字符串toString方法吗?