问题描述
classRect{privateIntegerlength;privateIntegerwidth;privateIntegernum;publicvoidsetNum(Integernum){this.num=num;}publicIntegergetNum(){returnnum;}@OverridepublicinthashCode(){finalintprime=31;intresult=1;result=prime*result+((length==null)?0:length.hashCode());result=prime*result+((num==null)?0:num.hashCode());result=prime*result+((width==null)?0:width.hashCode());returnresult;}@Overridepublicbooleanequals(Objectobj){if(this==obj)returntrue;if(obj==null)returnfalse;if(getClass()!=obj.getClass())returnfalse;Rectother=(Rect)obj;if(length==null){if(other.length!=null)returnfalse;}elseif(!length.equals(other.length))returnfalse;if(num==null){if(other.num!=null)returnfalse;}elseif(!num.equals(other.num))returnfalse;if(width==null){if(other.width!=null)returnfalse;}elseif(!width.equals(other.width))returnfalse;returntrue;}publicIntegergetWidth(){returnwidth;}publicvoidsetWidth(Integerwidth){this.width=width;}publicvoidsetLength(Integerlength){this.length=length;}publicIntegergetLength(){returnlength;}}classRect{intid;intlength;intwidth;publicRect(intid,intlength,intwidth){this.id=id;this.length=length;this.width=width;}publicinthashCode(){finalintprime=31;intresult=1;result=prime*result+id;result=prime*result+length;result=prime*result+width;returnresult;}publicbooleanequals(Objectobj){if(this==obj){returntrue;}if(obj==null){returnfalse;}if(getClass()!=obj.getClass()){returnfalse;}Rectother=(Rect)obj;if(id!=other.id){returnfalse;}if(length!=other.length){returnfalse;}if(width!=other.width){returnfalse;}returntrue;}}这两个对象的定义声明时占用内存有什么区别吗?