跳过七七头顶😜 量子程心
关注数: 91 粉丝数: 90 发帖数: 4,849 关注贴吧数: 33
有一个关于euquals()的问题 //DebugBoat.java //Teacher Notation //CAREFUL ---- Must be compiled before DebugEleven1.java is compiled and run!! public abstract class DebugBoat { String boatType = new String(); int passengers; String power = new String(); public DebugBoat(String bt) { boatType = bt; } public String toString() { return("This " + boatType +"boat carries " + passengers + " and is powered by " + power); } public abstract void setPower(); public abstract void setPassengers(); } -----------------------------------------这是我的abstract class------------------------------------------- //DebugRowBoat.java //Teacher Notation //CAREFUL ---- Must be compiled before DebugEleven1.java is compiled and run!! public class DebugRowboat extends DebugBoat { public DebugRowboat() { super("row"); } public void setPassengers() { super.passengers=2; } public void setPower() { super.power ="oars"; } } ---------------------------------------------这是我的subclass------------------------------------------- //DebugEleven3.java // Two boats should be equal // if they hold the same number of passengers // and have the same power source public class DebugEleven3 { public static void main(String args[]) { DebugRowboat redBoat = new DebugRowboat(); DebugRowboat blueBoat = new DebugRowboat(); redBoat.setPassengers(); blueBoat.setPassengers(); System.out.print("The two boats are"); if(redBoat.equals(blueBoat)) System.out.println(" equal"); else System.out.println(" not equal"); } } ----------------------------------------------结束---------------------------------------------------------- 按理说比较结果应该是 “equal”的 但是运行程序后 显示结果却是”not equal“ 请问有谁能给解答解答?
1 下一页