
{"id":2034,"date":"2020-08-13T10:08:41","date_gmt":"2020-08-13T02:08:41","guid":{"rendered":"http:\/\/admin.evshou.com\/?p=2034"},"modified":"2020-08-13T12:29:31","modified_gmt":"2020-08-13T04:29:31","slug":"2020java%e6%95%99%e7%a8%8b%ef%bc%9a%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e7%9a%84%e4%b8%89%e4%b8%aa%e4%bf%ae%e9%a5%b0%e7%ac%a6%e4%b9%8bstatic","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2034","title":{"rendered":"2020java\u6559\u7a0b\uff1a\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u4e2a\u4fee\u9970\u7b26\u4e4bstatic"},"content":{"rendered":"<h3>\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u4e2a\u4fee\u9970\u7b26\u4e4bstatic<\/h3>\n<p>\u5b9e\u4f8b\u5c5e\u6027<\/p>\n<pre>public class demos{\r\n    public static void main(String[] args) {\r\n        MyClass mc1=new MyClass();\r\n        mc1.a=10;\r\n        MyClass mc2=new MyClass();\r\n        mc2.a=20;\r\n        System.out.println(mc1.a+\"\\t\"+mc2.a);\r\n        \/\/\u8fd0\u884c\u7ed3\u679c 10   20<!--more-->\r\n\r\n\r\n    }\r\n}\r\nclass MyClass{\r\n    int a;\/\/\u5b9e\u4f8b\u5c5e\u6027\r\n    \/\/\u5b9e\u4f8b\u5c5e\u6027\u662f\u6bcf\u4e2a\u5bf9\u8c61\u5404\u81ea\u6301\u6709\u7684\u72ec\u7acb\u7a7a\u95f4\uff08\u591a\u4efd\uff09\uff0c\u5bf9\u8c61\u5355\u65b9\u9762\u4fee\u6539\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u5bf9\u8c61\u3002\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u9759\u6001\u5c5e\u6027<\/p>\n<pre>public class demos{\r\n    public static void main(String[] args) {\r\n        MyClass mc1=new MyClass();\r\n        mc1.a=10;\r\n        MyClass mc2=new MyClass();\r\n        mc2.a=20;\r\n        System.out.println(mc1.a+\"\\t\"+mc2.a);\r\n        \/\/\u8fd0\u884c\u7ed3\u679c 20   20\r\n    }\r\n}\r\nclass MyClass{\r\n    static int a;\/\/\u9759\u6001\u5c5e\u6027\r\n    \/*\r\n      \u9759\u6001\u5c5e\u6027\u662f\u6574\u4e2a\u7c7b\u5171\u540c\u6301\u6709\u7684\u5171\u4eab\u7a7a\u95f4\r\n      \u53ea\u6709\u4e00\u4efd\uff0c\u4efb\u4f55\u5bf9\u8c61\u4fee\u6539\uff0c\u90fd\u4f1a\u5f71\u54cd\u5176\u4ed6\u5bf9\u8c61\r\n     *\/\r\n}<\/pre>\n<p>\u4ec0\u4e48\u662f\u9759\u6001<\/p>\n<p>\u6982\u5ff5\uff1a<br \/>\n1.\u9759\u6001static\u53ef\u4ee5\u4fee\u9970\u5c5e\u6027\u548c\u65b9\u6cd5<br \/>\n2.\u79f0\u4e3a\u9759\u6001\u5c5e\u6027(\u7c7b\u5c5e\u6027)\u3001\u9759\u6001\u65b9\u6cd5(\u7c7b\u65b9\u6cd5)<br \/>\n3.\u9759\u6001\u6210\u5458\u662f\u5168\u7c7b\u6240\u6709\u5bf9\u8c61\u5171\u4eab\u7684\u6210\u5458<br \/>\n4.\u5728\u5168\u7c7b\u4e2d\u53ea\u6709\u4e00\u4efd\uff0c\u4e0d\u56e0\u521b\u5efa\u591a\u4e2a\u5bf9\u8c61\u800c\u4ea7\u751f\u591a\u4efd<br \/>\n5.\u4e0d\u5fc5\u521b\u5efa\u5bf9\u8c61\uff0c\u53ef\u76f4\u63a5\u901a\u8fc7\u7c7b\u540d\u8bbf\u95ee<\/p>\n<pre>public class demos{\r\n    public static void main(String[] args) {\r\n        MyClass mc1=new MyClass();\r\n        MyClass mc2=new MyClass();\r\n        mc1.a=10;\r\n        mc2.a=20;\r\n        mc1.b=100;\/\/\u81ea\u52a8\u8f6c\u6362\u6210 MyClass.b\r\n        mc2.b=200;\r\n        System.out.println(mc1.a+\"\\t\"+mc2.a);\r\n        \/\/\u8fd0\u884c\u7ed3\u679c 10   20\r\n        \/\/\u9759\u6001\u6210\u5458\u901a\u8fc7\u7c7b\u540d\u8bbf\u95ee  [\u7c7b\u540d.\u5c5e\u6027\u540d]\r\n        System.out.println(MyClass.b+\"\\t\"+MyClass.b);\r\n    }\r\n}\r\nclass MyClass{\r\n    int a;\r\n    static int b;\/\/\u9759\u6001\u5c5e\u6027\r\n}<\/pre>\n<p>\u9759\u6001\u65b9\u6cd5<\/p>\n<pre>public class demos{\r\n    public static void main(String[] args) {\r\n        MyClass.method1();\r\n        \/\/\u5728\u5176\u4ed6\u7c7b\u4e2d\uff0c\u901a\u8fc7 [\u7c7b\u540d.\u9759\u6001\u65b9\u6cd5\u540d] \u8bbf\u95ee\r\n    }\r\n}\r\nclass MyClass{\r\n    \/\/ static \u9759\u6001\u65b9\u6cd5\r\n    public static void method1(){\r\n        System.out.println(\"MyClass static method1()\");\r\n        \/\/\u5728\u672c\u7c7b\u4e2d\uff0c\u901a\u8fc7 [\u9759\u6001\u65b9\u6cd5\u540d] \u8bbf\u95ee\r\n        method2();\r\n    }\r\n    \/\/ static \u9759\u6001\u65b9\u6cd5\r\n    public static void method2(){\r\n        System.out.println(\"MyClass static method2()\");\r\n    }\r\n}<\/pre>\n<p>java\u4e2d\u7684\u65b9\u6cd5\u8c03\u7528\uff0c\u5206\u4e3a\u4e24\u79cd<br \/>\n1.\u9759\u6001\u5206\u6d3e<br \/>\n\u9759\u6001\u65b9\u6cd5\u4e2d\uff0c\u5141\u8bb8\u53c2\u6570\u5217\u8868\u4e0d\u540c\u7684\u91cd\u540d\u65b9\u6cd5\uff0c\u6307\u9759\u6001\u65b9\u6cd5\u4e4b\u95f4\u7684\u91cd\u8f7d<br \/>\n2.\u52a8\u6001\u5206\u6d3e<br \/>\n\u5728\u5177\u6709\u7ee7\u627f\u5173\u7cfb\u7684\u60c5\u51b5\u4e0b\uff0c\u8c03\u7528\u5b9e\u4f8b\u65b9\u6cd5\u65f6\uff0c\u81ea\u4f4e\u5411\u4e0a\u67e5\u627e\u53ef\u7528\u65b9\u6cd5\u7248\u672c\uff0c\u6307\u5b9e\u4f8b\u65b9\u6cd5\u7684\u8986\u76d6<\/p>\n<p>java\u865a\u62df\u673a\u65b9\u6cd5\u8c03\u7528\u6307\u4ee4<br \/>\n1.invokespacial \u79c1\u6709\u65b9\u6cd5 \uff0c\u6784\u9020\u65b9\u6cd5<br \/>\n2.invokeinterface \u8c03\u7528\u63a5\u53e3\u65b9\u6cd5<br \/>\n3.invokestatic \u8c03\u7528\u9759\u6001<br \/>\n4.invokevirtual \u8c03\u7528\u865a\u65b9\u6cd5(\u7236\u7c7b\u5b9a\u4e49\u7684\uff0c\u65e5\u540e\u88ab\u5b50\u7c7b\u8986\u76d6\u7684\u65b9\u6cd5)<br \/>\n5.invokedynamic \u8c03\u7528\u52a8\u6001\u94fe\u63a5\u65b9\u6cd5<\/p>\n<p>\u9759\u6001\u65b9\u6cd5\u5141\u8bb8\u76f4\u63a5\u8bbf\u95ee\u9759\u6001\u6210\u5458<br \/>\n\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u975e\u9759\u6001\u6210\u5458<br \/>\n\u9759\u6001\u65b9\u6cd5\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528this\u6216super\u5173\u952e\u5b57<br \/>\n\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u7ee7\u627f\uff0c\u4e0d\u80fd\u8986\u76d6\uff0c\u6ca1\u6709\u591a\u6001<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u4e2a\u4fee\u9970\u7b26\u4e4bstatic \u5b9e\u4f8b\u5c5e\u6027 public class demos{ public stati [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2034","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2034"}],"version-history":[{"count":6,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2034\/revisions"}],"predecessor-version":[{"id":2040,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2034\/revisions\/2040"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}