{"id":699,"date":"2022-10-05T23:24:47","date_gmt":"2022-10-05T15:24:47","guid":{"rendered":"https:\/\/qaqaq.top\/?p=699"},"modified":"2022-12-19T20:05:53","modified_gmt":"2022-12-19T12:05:53","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%ad-%e6%96%b9%e6%b3%95%e9%87%8d%e5%86%99%e7%9a%84%e7%bb%83%e4%b9%a0-3","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=699","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e2d)-\u65b9\u6cd5\u91cd\u5199\u7684\u7ec3\u4e60"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\u5982\u679c\u73b0\u5728\u7236\u7c7b\u7684\u4e00\u4e2a\u65b9\u6cd5\u5b9a\u4e49\u6210private\u8bbf\u95ee\u6743\u9650\uff0c\u5728\u5b50\u7c7b\u4e2d\u5c06\u6b64\u65b9\n\u6cd5\u58f0\u660e\u4e3adefault\u8bbf\u95ee\u6743\u9650\uff0c\u90a3\u4e48\u8fd9\u6837\u8fd8\u53eb\u91cd\u5199\u5417\uff1f\n\nNO<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P274;\n\n\/*\n\t\u5b9a\u4e49\u4e00\u4e2aManKind\u7c7b\uff0c\u5305\u62ec\n\t\u6210\u5458\u53d8\u91cfint sex\u548cint salary\uff1b\n\t\u65b9\u6cd5void manOrWoman()\uff1a\u6839\u636esex\u7684\u503c\u663e\u793a\u201cman\u201d(sex==1)\u6216\u8005\u201cwoman\u201d(sex==0)\uff1b\n\t\u65b9\u6cd5void employeed()\uff1a\u6839\u636esalary\u7684\u503c\u663e\u793a\u201cno job\u201d(salary==0)\u6216\u8005\u201c job\u201d(salary!=0)\u3002\n * \n * \n *\/\npublic class ManKind {\n\n\tprivate int sex;\/\/ \u6027\u522b\n\tprivate int salary;\/\/ \u85aa\u8d44\n\n\tpublic ManKind() {\n\t}\n\n\tpublic ManKind(int sex, int salary) {\n\t\tthis.sex = sex;\n\t\tthis.salary = salary;\n\t}\n\n\tpublic void manOrWoman() {\n\t\tif (sex == 1) {\n\t\t\tSystem.out.println(\"man\");\n\t\t} else if (sex == 0) {\n\t\t\tSystem.out.println(\"woman\");\n\t\t}\n\t}\n\n\tpublic void employeed() {\n\/\/\t\tif(salary == 0) {\n\/\/\t\t\tSystem.out.println(\"no job\");\n\/\/\t\t}else {\n\/\/\t\t\tSystem.out.println(\"job\");\n\/\/\t\t}\n\t\t\/\/ \u6216\n\t\tString jobInfo = (salary == 0) ? \"no job\" : \"job\";\n\t\tSystem.out.println(jobInfo);\n\t}\n\n\tpublic int getSex() {\n\t\treturn sex;\n\t}\n\n\tpublic void setSex(int sex) {\n\t\tthis.sex = sex;\n\t}\n\n\tpublic int getSalary() {\n\t\treturn salary;\n\t}\n\n\tpublic void setSalary(int salary) {\n\t\tthis.salary = salary;\n\t}\n\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P274;\n\n\/*\n\t\u5b9a\u4e49\u7c7bKids\u7ee7\u627fManKind\uff0c\u5e76\u5305\u62ec\n\t\u6210\u5458\u53d8\u91cfint yearsOld\uff1b\n\t\u65b9\u6cd5printAge()\u6253\u5370yearsOld\u7684\u503c\u3002\n * \n * \n *\/\npublic class Kids extends ManKind {\n\n\tprivate int yearsOld;\n\n\tpublic Kids() {\n\t}\n\n\tpublic Kids(int yearsOld) {\n\t\tthis.yearsOld = yearsOld;\n\t}\n\n\tpublic void printAge() {\n\t\tSystem.out.println(\"I am \" + yearsOld + \" years old.\");\n\t}\n\n\tpublic int getYearsOld() {\n\t\treturn yearsOld;\n\t}\n\n\tpublic void setYearsOld(int yearsOld) {\n\t\tthis.yearsOld = yearsOld;\n\t}\n\t\n\t\/*\n\t * \u4fee\u6539\u7ec3\u4e601.2\u4e2d\u5b9a\u4e49\u7684\u7c7bKids\uff0c\u5728Kids\u4e2d\u91cd\u65b0\u5b9a\u4e49employeed()\u65b9\u6cd5\uff0c\n\t * \u8986\u76d6\u7236\u7c7bManKind\u4e2d\u5b9a\u4e49\u7684employeed()\u65b9\u6cd5\uff0c\n\t * \u8f93\u51fa\u201cKids should study and no job.\u201d\n\t * \n\t *\/\n\t\n\tpublic void employeed() {\n\t\tSystem.out.println(\"Kids should study and no job.\");\n\t}\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P274;\n\/*\n * \u5b9a\u4e49\u7c7bKidsTest\uff0c\u5728\u7c7b\u7684main\u65b9\u6cd5\u4e2d\u5b9e\u4f8b\u5316Kids\u7684\u5bf9\u8c61someKid\uff0c\u7528\u8be5\u5bf9\u8c61\u8bbf\u95ee\u5176\u7236\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u53ca\u65b9\u6cd5\u3002\n * \n * \n *\/\npublic class KidsTest {\n\tpublic static void main(String&#91;] args) {\n\t\t\n\t\tKids someKid = new Kids(12);\n\t\t\n\t\tsomeKid.printAge();\n\t\t\n\t\tsomeKid.setSalary(0);\n\t\tsomeKid.setSex(1);\n\t\t\n\t\tsomeKid.employeed();\n\t\tsomeKid.manOrWoman();\n\n\t}\n\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P274;\n\npublic class Circle {\n\n\tprivate double radius;\/\/ \u534a\u5f84\n\n\tpublic Circle() {\n\t\tradius = 1.0;\n\t}\n\n\tpublic double getRadius() {\n\t\treturn radius;\n\t}\n\n\tpublic void setRadius(double radius) {\n\t\tthis.radius = radius;\n\t}\n\n\t\/\/\u8fd4\u56de\u5706\u7684\u9762\u79ef\n\tpublic double findArea() {\n\t\treturn Math.PI * radius * radius;\n\t}\n\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P274;\n\npublic class Cylinder extends Circle {\n\n\tprivate double length;\/\/ \u9ad8\n\n\tpublic Cylinder() {\n\t\tlength = 1.0;\n\t}\n\n\tpublic double getLength() {\n\t\treturn length;\n\t}\n\n\tpublic void setLength(double length) {\n\t\tthis.length = length;\n\t}\n\n\t\/\/\u8fd4\u56de\u5706\u67f1\u7684\u4f53\u79ef\n\tpublic double findVolume() {\n\t\treturn Math.PI * getRadius() * getRadius() * getLength();\n\/\/\t\treturn findArea() * getLength();\n\t}\n\t\n\t@Override\n\tpublic double findArea() {\/\/\u8fd4\u56de\u5706\u67f1\u7684\u8868\u9762\u79ef\n\t\treturn Math.PI * getRadius() * getRadius() * 2 + \n\t\t\t\t2 * Math.PI * getRadius() * getLength();\n\t}\n\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P274;\n\npublic class CylinderTest {\n\n\tpublic static void main(String&#91;] args) {\n\t\t\n\t\tCylinder cy = new Cylinder();\n\t\t\n\t\tcy.setRadius(2.1);\n\t\tcy.setLength(3.4);\n\t\tdouble volume = cy.findVolume();\n\t\tSystem.out.println(\"\u5706\u67f1\u7684\u4f53\u79ef\u4e3a\uff1a\" + volume);\n\t\t\n\t\t\/\/\u6ca1\u6709\u91cd\u5199findArea()\u65f6;\n\/\/\t\tdouble area = cy.findArea();\n\/\/\t\tSystem.out.println(\"\u5e95\u9762\u5706\u7684\u9762\u79ef\uff1a\" + area);\n\t\t\/\/\u91cd\u5199findArea()\u4ee5\u540e\n\t\tdouble area = cy.findArea();\n\t\tSystem.out.println(\"\u5706\u67f1\u7684\u8868\u9762\u79ef\uff1a\" + area);\n\t}\n}\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-699","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\/699"}],"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=699"}],"version-history":[{"count":2,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/699\/revisions"}],"predecessor-version":[{"id":2654,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/699\/revisions\/2654"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}