「Java」「Overriding」 Chapter3 Question1
Given:
Answer:
public class Test4 {
public static void main(String[] args) {
new FlyFish().result();
}
}
class Fish{
int num = 3;
static int total=30;
String jump() {
return "jump";
}
static String Speed() {
return "normal";
}
}
class FlyFish extends Fish{
int num = 10;
static int total=100;
String jump() {
return "Fly";
}
public static String Speed() {
return "fast";
}
void result() {
Fish f = new FlyFish();
System.out.println(f.num+" "+f.total+" "+f.jump()+" "+f.Speed()+" ");
FlyFish f1 = new FlyFish();
System.out.println(f1.num+" "+f1.total+" "+f1.jump()+" "+f1.Speed()+" ");
}
}
Answer:
留言
張貼留言