{"id":219294,"date":"2021-06-12T08:13:39","date_gmt":"2021-06-12T00:13:39","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=219294"},"modified":"2021-05-24T09:14:35","modified_gmt":"2021-05-24T01:14:35","slug":"java-upward-transformation","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/java-upward-transformation.html","title":{"rendered":"java\u591a\u6001\u7684\u5411\u4e0a\u8f6c\u578b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u7bc7\u5185\u5bb9\u91cc\u5c0f\u7f16\u7ed9\u5927\u5bb6\u6574\u7406\u7684\u662f\u4e00\u7bc7\u5173\u4e8ejava\u591a\u6001\u7684\u5411\u4e0a\u8f6c\u578b\u7684\u6982\u5ff5\u53ca\u5b9e\u4f8b\u5206\u6790\uff0c\u5bf9\u6b64\u6709\u5174\u8da3\u7684\u670b\u53cb\u4eec\u53ef\u4ee5\u8ddf\u7740\u5b66\u4e60\u4e0b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1\u3001\u8bf4\u660e<\/strong><\/span><\/div>\n

\u5411\u4e0a\u8f6c\u578b\u5c31\u662f\u628a\u4e00\u4e2a\u5b50\u7c7b\u5f15\u7528\u7ed9\u4e00\u4e2a\u7236\u7c7b\u5f15\u7528\uff0c\u4e5f\u5c31\u662f\u7236\u7c7b\u5f15\u7528 \u5f15\u7528\u4e86\u5b50\u7c7b\u7684\u5bf9\u8c61\uff0c\u5373\u7236\u7c7b \u7236\u7c7b\u5bf9\u8c61 = \u5b50\u7c7b\u5b9e\u4f8b\u3002<\/p>\n

\u6b64\u65f6\u901a\u8fc7\u7236\u7c7b\u5f15\u7528\u53d8\u91cf\u8c03\u7528\u7684\u65b9\u6cd5\u662f\u5b50\u7c7b\u8986\u76d6\u6216\u7ee7\u627f\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u7236\u7c7b\u7684\u65b9\u6cd5\u3002\u4f46\u662f\u8c03\u7528\u7684\u5c5e\u6027\u8fd8\u662f\u7236\u7c7b\u7684\u5c5e\u6027\u3002<\/p>\n

2\u3001\u5b9e\u4f8b<\/strong><\/span><\/div>\n
\r\nclass Animal {\r\n    public String name;\r\n    public void eat() {\r\n        System.out.println(this.name + \" \u6b63\u5728\u5403\");\r\n    }\r\n}\r\nclass Cat extends Animal {\r\n     \r\n}\r\npublic class Test extends TestDemo {\r\n  \r\n    public static void main(String[] args) {\r\n        \/\/\u7236\u7c7b\u5f15\u7528 \u5f15\u7528\u4e86 \u5b50\u7c7b\u5f15\u7528\u6240\u5f15\u7528\u7684\u5bf9\u8c61\r\n        Cat cat = new Cat();\r\n        Animal animal = cat;\/\/\u5411\u4e0a\u8f6c\u578b\r\n    }\r\n}\r\n<\/pre>\n

\u77e5\u8bc6\u70b9\u6269\u5145\uff1a<\/strong><\/p>\n

Java\u5141\u8bb8\u628a\u5b50\u7c7b\u5bf9\u8c61\u8d4b\u503c\u7ed9\u7236\u7c7b\u7684\u5f15\u7528\u53d8\u91cf\uff0c\u4e0d\u7528\u505a\u4efb\u4f55\u5f3a\u5236\u8f6c\u6362\uff0c\u7cfb\u7edf\u81ea\u52a8\u5b8c\u6210\u3002\u5411\u4e0a\u8f6c\u578b\u6765\u81ea\u4e8e\u81ea\u4e0b\u800c\u4e0a\u7684\u7ee7\u627f\u5173\u7cfb\uff0c\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\uff0c\u5b50\u7c7b\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u7236\u7c7b\uff0c\u6240\u4ee5\u5411\u4e0a\u8f6c\u578b\u7684\u64cd\u4f5c\u5176\u5b9e\u662f\u60c5\u7406\u4e4b\u4e2d\u7684\u3002<\/p>\n

\u4e0b\u9762\u4f9d\u7167\u7b80\u5355\u7684\u4ee3\u7801\uff0c\u6765\u8bd5\u7740\u7406\u89e3\u5411\u4e0a\u8f6c\u578b\u7684\u6982\u5ff5\u4e0e\u597d\u5904\u3002<\/p>\n

\r\npackage com.my.pac14;\r\n \r\n\/**\r\n * @auther Summerday\r\n *\/\r\npublic class DynamicBinding {\r\n    \/\/Object\u662f\u6240\u6709\u7c7b\u7684\u8d85\u7c7b\uff0c\u6839\u636e\u5411\u4e0a\u8f6c\u578b\uff0c\u8be5\u65b9\u6cd5\u53ef\u4ee5\u63a5\u53d7\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\r\n    public static void test(Object x) {\r\n        System.out.println(x.toString());\r\n    }\r\n \r\n    public static void main(String[] args) {\r\n        test(new PrimaryStudent());\/\/Student\r\n        test(new Student());\/\/Student\r\n        test(new Person());\/\/Person\r\n        test(new Object());\/\/java.lang.Object@1b6d3586\r\n    }\r\n}\r\n \r\nclass Person extends Object {\r\n    @Override\r\n    public String toString() {\r\n        return \"Person\";\r\n    }\r\n}\r\n \r\nclass Student extends Person {\r\n    @Override\r\n    public String toString() {\r\n        return \"Student\";\r\n    }\r\n}\r\n \r\nclass PrimaryStudent extends Student {\r\n}\r\n<\/pre>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8ejava\u591a\u6001\u7684\u5411\u4e0a\u8f6c\u578b\u7684\u6982\u5ff5\u53ca\u5b9e\u4f8b\u5206\u6790\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5411\u4e0a\u8f6c\u578b\u5c31\u662f\u628a\u4e00\u4e2a\u5b50\u7c7b\u5f15\u7528\u7ed9\u4e00\u4e2a\u7236\u7c7b\u5f15\u7528\uff0c\u4e5f\u5c31\u662f\u7236\u7c7b\u5f15\u7528 \u5f15\u7528\u4e86\u5b50\u7c7b\u7684\u5bf9\u8c61\uff0c\u5373\u7236\u7c7b \u7236\u7c7b\u5bf9\u8c61 = \u5b50\u7c7b\u5b9e\u4f8b\u3002 […]<\/p>\n","protected":false},"author":1479,"featured_media":160442,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-219294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=219294"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219294\/revisions"}],"predecessor-version":[{"id":219296,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219294\/revisions\/219296"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/160442"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=219294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=219294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=219294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}