「Java」「Overriding」 Chapter3 Question1

Given:
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:




留言

這個網誌中的熱門文章

[Excel]國曆轉農曆VBA

「CSS」「div區塊介紹」 三欄式網頁排版設計

「生活」眉毛觀人