• 2021-04-14 问题

    请阅读下面的程序,写出运行结果,如果编译失败,写明失败原因。 abstract class Animal{ public final abstract void eat(); } class Cat extends Animal{ public void eat(){ System.out.println("cat...fish"); } } class CatDemo{ public static void main(String[] args){ Animal a = new Cat(); a.eat(); } }

    请阅读下面的程序,写出运行结果,如果编译失败,写明失败原因。 abstract class Animal{ public final abstract void eat(); } class Cat extends Animal{ public void eat(){ System.out.println("cat...fish"); } } class CatDemo{ public static void main(String[] args){ Animal a = new Cat(); a.eat(); } }

  • 2021-04-14 问题

    (7-7)阅读程序,写出程序运行结果。 //写出程序运行结果 class Eye {// 猫的眼睛类 private String color; public Eye(String color) { this.color = color; } } class Cat {// 猫类 private String name; private Eye eye; public Cat(String name, Eye eye) { this.name = name; this.eye = eye; } public boolean equals(Object obj) { Cat cat = (Cat) obj; if (this.name.equals(cat.name) && this.eye == cat.eye) return true; return false; } } public class CatDemo { public static void main(String[] args) { Eye e1=new Eye("蓝色"); Cat tom1=new Cat("Tom",e1); Cat tom2=new Cat("Tom",e1); System.out.println(tom1==tom2); System.out.println(tom1.equals(tom2)); } }

    (7-7)阅读程序,写出程序运行结果。 //写出程序运行结果 class Eye {// 猫的眼睛类 private String color; public Eye(String color) { this.color = color; } } class Cat {// 猫类 private String name; private Eye eye; public Cat(String name, Eye eye) { this.name = name; this.eye = eye; } public boolean equals(Object obj) { Cat cat = (Cat) obj; if (this.name.equals(cat.name) && this.eye == cat.eye) return true; return false; } } public class CatDemo { public static void main(String[] args) { Eye e1=new Eye("蓝色"); Cat tom1=new Cat("Tom",e1); Cat tom2=new Cat("Tom",e1); System.out.println(tom1==tom2); System.out.println(tom1.equals(tom2)); } }

  • 1