{"id":755,"date":"2022-10-07T18:31:05","date_gmt":"2022-10-07T10:31:05","guid":{"rendered":"https:\/\/qaqaq.top\/?p=755"},"modified":"2022-11-27T12:39:55","modified_gmt":"2022-11-27T04:39:55","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%ad-object%e7%b1%bb%e7%bb%bc%e5%90%88%e7%bb%83%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=755","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e2d)-Object\u7c7b\u7efc\u5408\u7ec3\u4e60"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P302;\r\n\r\npublic class GeometricObject {\r\n\r\n\tprotected String color;\r\n\tprotected double weight;\r\n\r\n\tprotected GeometricObject() {\r\n\t\tsuper();\r\n\t\tthis.color = \"white\";\r\n\t\tthis.weight = 1.0;\r\n\t}\r\n\r\n\tprotected GeometricObject(String color, double weight) {\r\n\t\tsuper();\r\n\t\tthis.color = color;\r\n\t\tthis.weight = weight;\r\n\t}\r\n\r\n\tpublic String getColor() {\r\n\t\treturn color;\r\n\t}\r\n\r\n\tpublic void setColor(String color) {\r\n\t\tthis.color = color;\r\n\t}\r\n\r\n\tpublic double getWeight() {\r\n\t\treturn weight;\r\n\t}\r\n\r\n\tpublic void setWeight(double weight) {\r\n\t\tthis.weight = weight;\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P302;\r\n\r\npublic class Circle extends GeometricObject {\r\n\r\n\tprivate double radius;\r\n\r\n\tpublic Circle() {\r\n\t\tsuper();\r\n\t\tradius = 1.0;\r\n\/\/\t\tcolor = \"white\";\r\n\/\/\t\tweight = 1.0;\r\n\t}\r\n\r\n\tpublic Circle(double radius) {\r\n\t\tsuper();\r\n\t\tthis.radius = radius;\r\n\t}\r\n\r\n\tpublic Circle(double radius, String color, double weight) {\r\n\t\tsuper(color, weight);\r\n\t\tthis.radius = radius;\r\n\t}\r\n\r\n\tpublic double getRadius() {\r\n\t\treturn radius;\r\n\t}\r\n\r\n\tpublic void setRadius(double radius) {\r\n\t\tthis.radius = radius;\r\n\t}\r\n\r\n\t\/\/ \u6c42\u5706\u7684\u9762\u79ef\r\n\tpublic double findArea() {\r\n\t\treturn 3.14 * radius * radius;\r\n\t}\r\n\r\n\t\/\/ \u6bd4\u8f83\u4e24\u4e2a\u5706\u7684\u534a\u5f84\u662f\u5426\u76f8\u7b49\uff0c\u5982\u76f8\u7b49\uff0c\u8fd4\u56detrue\u3002\r\n\t@Override\r\n\tpublic boolean equals(Object obj) {\r\n\t\tif (this == obj) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tif (obj instanceof Circle) {\r\n\t\t\tCircle c = (Circle) obj;\r\n\t\t\treturn this.radius == c.radius;\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString() {\r\n\t\treturn \"Circle &#91;radius=\" + radius + \"]\";\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P302;\r\n\/*\r\n * \u5199\u4e00\u4e2a\u6d4b\u8bd5\u7c7b\uff0c\u521b\u5efa\u4e24\u4e2aCircle\u5bf9\u8c61\uff0c\u5224\u65ad\u5176\u989c\u8272\u662f\u5426\u76f8\u7b49\uff1b\r\n * \u5229\u7528equals\u65b9\u6cd5\u5224\u65ad\u5176\u534a\u5f84\u662f\u5426\u76f8\u7b49\uff1b\u5229\u7528toString()\u65b9\u6cd5\u8f93\u51fa\u5176\u534a\u5f84\u3002\r\n * \r\n * \r\n * \r\n *\/\r\npublic class CircleTest {\r\n\t\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\tCircle circle1 = new Circle(2.3);\t\t\r\n\t\tCircle circle2 = new Circle(3.3, new String(\"white\"), 2.0);\r\n\t\t\r\n\t\tSystem.out.println(\"\u989c\u8272\u662f\u5426\u76f8\u7b49\uff1a\" + circle1.getColor().equals(circle2.getColor()));\r\n\t\t\r\n\t\tSystem.out.println(\"\u534a\u5f84\u662f\u5426\u76f8\u7b49:\" + circle1.equals(circle2));\r\n\t\t\r\n\t\tSystem.out.println(circle1);\r\n\t\tSystem.out.println(circle2.toString());\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-755","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/755"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=755"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/755\/revisions"}],"predecessor-version":[{"id":756,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/755\/revisions\/756"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}