{"id":882,"date":"2022-10-12T22:58:35","date_gmt":"2022-10-12T14:58:35","guid":{"rendered":"https:\/\/qaqaq.top\/?p=882"},"modified":"2022-11-27T12:39:53","modified_gmt":"2022-11-27T04:39:53","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%8b-%e6%8a%bd%e8%b1%a1%e7%9a%84%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af%e4%b8%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=882","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0b)-\u62bd\u8c61\u7684\u5e94\u7528\u573a\u666f\u4e3e\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P344;\r\n\r\npublic abstract 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 abstract double findArea();\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P344;\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.P344;\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.P344;\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-882","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\/882"}],"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=882"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":883,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/882\/revisions\/883"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}