public final class Hw7pr2
{
public static void main(String[] args)
{
System.out.println(“Starting …….”);
Scanner scan =new scanner(system.in);
log("Starting...");
Pet pet = new Pet();
work_like(pet);
pet = new Fish();
work_like(pet);
pet = new dog();
work_like(pet);
pet = new cat();
work_like(pet);
log("Done.");
}
public static void work_like(Pet aPet)
{ aPet.walk();
}
private static class Pet
{
Public:
Char name[10], color[10];
void prop()
{
log("pet is: ");
system.out.println(“enter Name and color of pet”);
name=scan.nextchar();
color =scan.nextchar();
}
}
private static final class Fish extends Pet
{
@Override void prop()
{
log("pet is fish...");
System.out.println(“Pet is fish”);
}
}
private static final class dog extends Pet
{
Char breed;
Int weight;
@Override void prop()
{
log("Pet is Dog ");
system.out.println(“Enter the breed”);
breed =scan.nextchar();
system.out.println(“Enter weight of the dog”);
weight=scan.nextchar();
}
}
private static final class cat extends Pet
{
Char coat;
@Override void prop()
{
log("Pet is cat");
system.out.println(“Enter Name and color of pet”);
coat =scan.nextchar();
}
}
private static void log(String aMessage)
{
System.out.println(aMessage);
}
}
它一直说我有很多非法角色,但我不知道那是什么,有人可以帮助我吗?
答案 0 :(得分:4)
如果您从MS Word复制了该行,则该行看起来不对(点):
System.out.println(“Starting …….”);