请在 下方输入 要搜索的题目:

编写一个Java应用程序,该程序中有1个Cat类继承Object类,具有三个成员属性String name、int furColor、int height,一个构造方法Cat(String name, int furColor, int height, int weight),并且重写Cat类的toString()和equals(Object obj)成员方法。具体要求如下:(1)重写toString成员方法,返回值是成员属性String name的值。 (2)重写equals成员方法,如果两个Cat对象的furColor和height属性相等那么返回值是true,否则返回值是false。

编写一个Java应用程序,该程序中有1个Cat类继承Object类,具有三个成员属性String name、int furColor、int height,一个构造方法Cat(String name, int furColor, int height, int weight),并且重写Cat类的toString()和equals(Object obj)成员方法。具体要求如下:(1)重写toString成员方法,返回值是成员属性String name的值。 (2)重写equals成员方法,如果两个Cat对象的furColor和height属性相等那么返回值是true,否则返回值是false。

发布时间:2025-05-17 18:30:11
推荐参考答案 ( 由 快搜搜题库 官方老师解答 )
联系客服
答案:【计分规则】: class Cat{ int color ; int height,weight ; public Cat(String name,int color,int height,int weight){ this.name=name ; this.color = color ; this.height = height ; this.weight = weight ; } public String toString(){ return this.name; } public boolean equals(Object obj){ if(obj==null) return false ; else{ if(obj instanceof Cat){ Cat c =(Cat) obj ; if(c.color==this.color && c.height==this.height) return true ; } } return false ; }}
专业技术学习
专业技术学习
搜搜题库系统