{"id":735,"date":"2022-10-06T22:59:18","date_gmt":"2022-10-06T14:59:18","guid":{"rendered":"https:\/\/qaqaq.top\/?p=735"},"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-%e5%a4%9a%e6%80%81%e6%80%a7%e7%bb%83%e4%b9%a0%ef%bc%9a%e5%87%a0%e4%bd%95%e5%9b%be%e5%bd%a2","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=735","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e2d)-\u591a\u6001\u6027\u7ec3\u4e60\uff1a\u51e0\u4f55\u56fe\u5f62"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P292;\r\n\r\npublic class GeometricObject {\r\n\r\n\tprotected String color;\r\n\tprotected double weight;\r\n\r\n\tpublic 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\t\r\n\tpublic double findArea() {\r\n\t\treturn 0.0;\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.P292;\r\n\r\npublic class Circle extends GeometricObject {\r\n\r\n\tprivate double radius;\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\tpublic double findArea() {\r\n\t\treturn 3.14 * radius * radius;\r\n\t}\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P292;\r\n\r\npublic class MyRectangle extends GeometricObject {\r\n\r\n\tprivate double width;\r\n\tprivate double height;\r\n\r\n\tpublic MyRectangle(double width, double height, String color, double weight) {\r\n\t\tsuper(color, weight);\r\n\t\tthis.width = width;\r\n\t\tthis.height = height;\r\n\t}\r\n\r\n\tpublic double getWidth() {\r\n\t\treturn width;\r\n\t}\r\n\r\n\tpublic void setWidth(double width) {\r\n\t\tthis.width = width;\r\n\t}\r\n\r\n\tpublic double getHeight() {\r\n\t\treturn height;\r\n\t}\r\n\r\n\tpublic void setHeight(double height) {\r\n\t\tthis.height = height;\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic double findArea() {\r\n\t\treturn width * height;\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.P292;\r\n\/*\r\n\t\u5b9a\u4e49\u4e00\u4e2a\u6d4b\u8bd5\u7c7bGeometricTest\uff0c\r\n\t\u7f16\u5199equalsArea\u65b9\u6cd5\u6d4b\u8bd5\u4e24\u4e2a\u5bf9\u8c61\u7684\u9762\u79ef\u662f\u5426\u76f8\u7b49\uff08\u6ce8\u610f\u65b9\u6cd5\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u5229\u7528\u52a8\u6001\u7ed1\u5b9a\u6280\u672f\uff09\uff0c\r\n\t\u7f16\u5199displayGeometricObject\u65b9\u6cd5\u663e\u793a\u5bf9\u8c61\u7684\u9762\u79ef\uff08\u6ce8\u610f\u65b9\u6cd5\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u5229\u7528\u52a8\u6001\u7ed1\u5b9a\u6280\u672f\uff09\u3002\r\n * \r\n * \r\n * \r\n * \r\n * \r\n * \r\n * \r\n *\/\r\npublic class GeometricTest {\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\t\r\n\t\tGeometricTest test = new GeometricTest();\r\n\t\t\r\n\t\tCircle c1 = new Circle(2.3, \"white\", 1.0);\r\n\t\ttest.displayGeometricObject(c1);\r\n\t\tCircle c2 = new Circle(3.3, \"white\", 1.0);\r\n\t\ttest.displayGeometricObject(c2);\r\n\t\t\r\n\t\tboolean isEquals = test.equalsArea(c1, c2);\r\n\t\tSystem.out.println(\"c1\u548cc2\u7684\u9762\u79ef\u662f\u5426\u76f8\u7b49\uff1a\" + isEquals);\r\n\t\t\r\n\t\tMyRectangle rect = new MyRectangle(2.1, 3.4, \"red\", 2.0);\r\n\t\ttest.displayGeometricObject(rect);\r\n\t}\r\n\t\r\n\tpublic void displayGeometricObject(GeometricObject o) {\/\/GeometricObject o = new Circle(...)\r\n\t\t\r\n\t\tSystem.out.println(\"\u9762\u79ef\u4e3a\uff1a\" + o.findArea());\r\n\t\t\r\n\t}\r\n\t\r\n\t\/\/\u6d4b\u8bd5\u4e24\u4e2a\u5bf9\u8c61\u7684\u9762\u79ef\u662f\u5426\u76f8\u7b49\r\n\tpublic boolean equalsArea(GeometricObject o1,GeometricObject o2) {\r\n\r\n\t\treturn o1.findArea() == o2.findArea();\r\n\t}\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-735","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\/735"}],"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=735"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions"}],"predecessor-version":[{"id":736,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions\/736"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}