{"rsdb":{"rid":"308972","subhead":"","postdate":"0","aid":"224134","fid":"115","uid":"1","topic":"1","content":"
\n\t\t\t\t\t\t\t\t\n \t\t\t\t\t\t\t\t \n\t\t\t\t\t\t
\n \n

instanceof \uff1a<\/h1>\n
\u5982 \uff1aAnimal d = new Dog();<\/span><\/div>\n
<\/span>if(d instanceof Dog)\/\/\u5982\u679cd\u662fDog\u7684\u5b9e\u4f8b<\/span><\/div>\n
<\/span>{d.voice;}<\/span><\/div>\n

\u4e3a\u4ec0\u4e48\u9700\u8981\u62bd\u8c61\u7c7b\uff1f\u5982\u4f55\u5b9a\u4e49\u62bd\u8c61\u7c7b\uff1f<\/span><\/h1>\n
\u662f\u4e00\u79cd\u6a21\u677f\u6a21\u5f0f\u3002\u62bd\u8c61\u7c7b\u4e3a\u6240\u6709\u5b50\u7c7b\u63d0\u4f9b\u4e86\u4e00\u4e2a\u901a\u7528\u6a21\u677f\uff0c\u5b50\u7c7b\u53ef\u4ee5\u5728\u8fd9\u4e2a\u6a21\u677f\u57fa\u7840\u4e0a\u8fdb\u884c\u6269\u5c55\u3002<\/strong><\/span><\/div>\n
\u901a\u8fc7\u62bd\u8c61\u7c7b\uff0c\u53ef\u4ee5\u907f\u514d\u5b50\u7c7b\u8bbe\u8ba1\u7684\u968f\u610f\u6027<\/strong><\/span>\u3002\u901a\u8fc7\u62bd\u8c61\u7c7b\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u505a\u5230\u4e25\u683c\u9650\u5236\u5b50\u7c7b\u7684\u8bbe\u8ba1\uff0c<\/span><\/div>\n
\u4f7f\u5b50\u7c7b\u4e4b\u95f4\u53ef\u4ee5\u66f4\u52a0\u901a\u7528\u3002<\/span><\/div>\n

\u8981\u70b9\uff1a<\/strong><\/span><\/h2>\n
\u6709\u62bd\u8c61\u65b9\u6cd5\u7684\u7c7b\u53ea\u80fd\u5b9a\u4e49\u6210\u62bd\u8c61\u7c7b\u3002<\/span><\/div>\n
\u62bd\u8c61\u7c7b\u4e0d\u80fd\u5b9e\u4f8b\u5316\uff0c\u5373\u4e0d\u80fd\u7528new\u6765\u5b9e\u4f8b\u5316\u62bd\u8c61\u7c7b\u3002<\/span><\/div>\n
\u62bd\u8c61\u7c7b\u53ef\u4ee5\u5305\u542b\u5c5e\u6027\u3001\u65b9\u6cd5\u3001\u6784\u9020\u65b9\u6cd5\u3002\u4f46\u662f\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u7528\u6765new\u5b9e\u4f8b\uff0c<\/span><\/div>\n
\u53ea\u80fd\u7528\u6765\u88ab\u5b50\u7c7b\u8c03\u7528\u3002<\/span><\/div>\n
\u62bd\u8c61\u7c7b\u53ea\u80fd\u7528\u6765\u7ee7\u627f\u3002<\/span><\/div>\n
\u62bd\u8c61\u6cd5\u65b9\u6cd5\u5fc5\u987b\u88ab\u5b50\u7c7b\u5b9e\u73b0\u3002<\/span><\/div>\n

<\/span><\/div>\n

<\/span><\/div>\n

\u63a5\u53e3<\/span><\/h1>\n
\u63a5\u53e3\u5c31\u662f\u6bd4\u62bd\u8c61\u7c7b\u66f4\u62bd\u8c61\u7684\u7c7b\uff0c\u63a5\u53e3\u4e2d\u53ea\u6709\u5e38\u91cf\u3001\u62bd\u8c61\u65b9\u6cd5\uff01\uff01<\/span><\/div>\n

<\/span><\/div>\n
\u5982<\/span><\/div>\n
public interface MyInterface{<\/span><\/div>\n
String Max_GREAD=\"BOSS\";\/\/\u65e0\u8bba\u4f60\u524d\u9762\u662f\u4e0d\u662f\u5199public static final \u5b83\u59cb\u7ec8\u90fd\u6709<\/span><\/div>\n
public abstract void test01();\/\/\u800c\u5bf9\u4e8e\u65b9\u6cd5\u5fc5\u987b\u662fpublic,\u81f3\u4e8eabstract\u5199\u4e0d\u5199\u90fd\u6709<\/span><\/div>\n
}<\/span><\/div>\n

\u603b\u7ed3\uff1a\u4e3a\u4ec0\u4e48\u9700\u8981\u63a5\u53e3\uff1f\u63a5\u53e3\u548c\u62bd\u8c61\u7c7b\u7684\u533a\u522b\uff1f<\/span><\/h2>\n
-\u63a5\u53e3\u5c31\u662f\u6bd4\u201c\u62bd\u8c61\u7c7b\u201d\u8fd8\u201c\u62bd\u8c61\u201d\u7684\u201c\u62bd\u8c61\u7c7b\u201d\uff0c\u53ef\u4ee5\u66f4\u52a0\u89c4\u8303\u7684\u5bf9\u5b50\u7c7b\u8fdb\u884c\u7ea6\u675f\u3002<\/span><\/div>\n
\u5168\u9762\u5730\u4e13\u4e1a\u5730\u5b9e\u73b0\u4e86\uff1a\u89c4\u8303\u548c\u5177\u4f53\u5b9e\u73b0\u7684\u5206\u79bb\u3002<\/strong><\/span><\/div>\n
-\u63a5\u53e3\u5c31\u662f\u89c4\u8303\uff0c\u5b9a\u4e49\u7684\u662f\u4e00\u7ec4\u89c4\u5219\uff0c\u4f53\u73b0\u4e86\u73b0\u5b9e\u4e16\u754c\u4e2d\u201c\u5982\u679c\u662f\u4f60...\u5219\u5fc5\u987b\u80fd...\u201d\u7684\u601d\u60f3\u3002<\/strong><\/span><\/div>\n
-\u63a5\u53e3\u7684\u672c\u8d28\u662f\u5951\u7ea6\uff0c\u5c31\u60f3\u6211\u4eec\u4eba\u95f4\u7684\u6cd5\u5f8b\u4e00\u6837\u3002\u5236\u5b9a\u597d\u540e\u5927\u5bb6\u90fd\u9075\u5b88<\/strong>\u3002<\/span><\/div>\n
-\u9879\u76ee\u7684\u5177\u4f53\u9700\u6c42\u662f\u591a\u53d8\u7684\uff0c\u6211\u4eec\u5fc5\u987b\u4ee5\u4e0d\u53d8\u5e94\u4e07\u53d8\u624d\u80fd\u4ece\u5bb9\u5f00\u53d1\uff0c\u6b64\u5904\u7684\u201c\u4e0d\u53d8\u201d\u5c31\u662f\u201c\u89c4\u8303\u201d\u3002<\/strong><\/span><\/div>\n
\u56e0\u6b64\uff0c\u6211\u4eec\u5f00\u53d1\u9879\u76ee\u5f80\u5f80\u90fd\u662f\u9762\u5411\u63a5\u53e3\u7f16\u7a0b\uff01<\/strong><\/span><\/div>\n

<\/div>\n
\u5b50\u7c7b\u901a\u8fc7implements\u6765\u5b9e\u73b0\u63a5\u53e3\u4e2d\u7684\u89c4\u8303<\/strong><\/span><\/div>\n
\u63a5\u53e3\u4e0d\u80fd\u521b\u5efa\u5b9e\u4f8b\uff0c\u4f46\u662f\u53ef\u7528\u4e8e\u58f0\u660e\u5f15\u7528\u53d8\u91cf\u7c7b\u578b\u3002<\/strong><\/span><\/div>\n
\u4e00\u4e2a\u7c7b\u5b9e\u73b0\u4e86\u63a5\u53e3\uff0c\u5fc5\u987b\u5b9e\u73b0\u63a5\u53e3\u4e2d\u6240\u6709\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u8fd9\u4e9b\u65b9\u6cd5\u53ea\u80fd\u662fpublic\u7684\u3002<\/strong><\/span><\/div>\n
\u63a5\u53e3\u652f\u6301\u591a\u7ee7\u627f\u3002<\/strong><\/span><\/div>\n


\n\u5185\u90e8\u7c7b\uff1a<\/h1>\n
\u4e00\u822c\u60c5\u51b5\uff0c\u6211\u4eec\u628a\u7c7b\u5b9a\u4e49\u6210\u72ec\u7acb\u7684\u5355\u5143\u3002\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u628a\u4e00\u4e2a\u7c7b\u653e\u5728\u53e6\u4e00\u4e2a\u7c7b\u7684\u5185\u90e8\u5b9a\u4e49\uff0c\u79f0\u4e3a\u5185\u90e8\u7c7b<\/strong>\u3002<\/span><\/div>\n

\u5185\u90e8\u7c7b\u7684\u4f5c\u7528\uff1a<\/span><\/h2>\n
1\u3001\u5185\u90e8\u7c7b\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u5c01\u88c5\u3002\u53ea\u80fd\u8ba9\u5916\u90e8\u7c7b\u76f4\u63a5\u8bbf\u95ee<\/strong>\uff0c\u4e0d\u5141\u8bb8\u540c\u4e00\u4e2a\u5305\u4e2d\u7684\u5176\u4ed6\u7c7b\u76f4\u63a5\u8bbf\u95ee\u3002<\/span><\/div>\n
2\u3001\u5185\u90e8\u7c7b\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u79c1\u6709\u5c5e\u6027\uff0c\u5185\u90e8\u7c7b\u88ab\u5f53\u6210\u5176\u5916\u90e8\u7c7b\u7684\u6210\u5458\u3002<\/span><\/div>\n
\u4f46\u5916\u90e8\u7c7b\u4e0d\u80fd\u8bbf\u95ee\u5185\u90e8\u7c7b\u7684\u5185\u90e8\u5c5e\u6027\u3002<\/span><\/div>\n


<\/span>\u5185\u90e8\u7c7b\u7684\u4f7f\u7528\u573a\u5408\uff1a<\/span><\/h2>\n
\u7531\u4e8e\u5185\u90e8\u7c7b\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u5c01\u88c5\u7279\u6027\uff0c\u5e76\u4e14\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u5c5e\u6027\u3002<\/span><\/div>\n
\u6240\u4ee5\uff0c\u901a\u5e38\u5185\u90e8\u7c7b\u5728\u53ea\u4e3a\u6240\u5728\u5916\u90e8\u7c7b\u63d0\u4f9b\u670d\u52a1\u7684\u60c5\u51b5\u4e0b\u4f18\u5148\u4f7f\u7528<\/strong>\u3002<\/span><\/div>\n


<\/span>\u5185\u90e8\u7c7b\u7684\u5206\u7c7b\uff1a<\/span><\/h2>\n
1\u3001\u6210\u5458\u5185\u90e8\u7c7b\uff08\u53ef\u4ee5\u4f7f\u7528private\u3001protected\u3001public\u4efb\u610f\u8fdb\u884c\u4fee\u9970\u3002\u7c7b\u6587\u4ef6\uff1a\u5916\u90e8\u7c7b$\u5185\u90e8\u7c7b.class\uff09<\/strong><\/span><\/div>\n
<\/span>a)\u975e\u9759\u6001\u5185\u90e8\u7c7b\uff08\u5916\u90e8\u7c7b\u91cc\u4f7f\u7528\u975e\u9759\u6001\u5185\u90e8\u7c7b\u548c\u5e73\u65f6\u4f7f\u7528\u5176\u5b83\u7c7b\u6ca1\u6709\u4ec0\u4e48\u4e0d\u540c\uff09<\/strong><\/span><\/div>\n
<\/span>i.\u975e\u9759\u6001\u5185\u90e8\u7c7b\u5fc5\u987b\u5bc4\u5b58\u5728\u4e00\u4e2a\u5916\u90e8\u7c7b\u5bf9\u8c61\u91cc\u3002\u56e0\u6b64\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u975e\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\u90a3\u4e48\u4e00\u5b9a\u5b58\u5728<\/strong><\/span><\/div>\n
<\/span> \u5bf9\u5e94\u7684\u5916\u90e8\u7c7b\u5bf9\u8c61\u3002\u975e\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\u5355\u72ec\u5c5e\u4e8e\u5916\u90e8\u7c7b\u7684\u67d0\u4e2a\u5bf9\u8c61\u3002<\/span><\/strong><\/span><\/div>\n
<\/span>ii.\u975e\u9759\u6001\u5185\u90e8\u7c7b\u53ef\u4ee5\u4f7f\u7528\u5916\u90e8\u7c7b\u7684\u6210\u5458\uff0c\u4f46\u662f\u5916\u90e8\u7c7b\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u975e\u9759\u6001\u5185\u90e8\u7c7b\u6210\u5458\u3002<\/strong><\/span><\/div>\n
<\/span>iii.\u975e\u9759\u6001\u5185\u90e8\u7c7b\u4e0d\u80fd\u6709\u9759\u6001\u65b9\u6cd5\u3001\u9759\u6001\u5c5e\u6027\u3001\u9759\u6001\u521d\u59cb\u5316\u5757\u3002<\/strong><\/span><\/div>\n
<\/span>iv.\u9759\u6001\u6210\u5458\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001\u6210\u5458\uff1a\u5916\u90e8\u7c7b\u7684\u9759\u6001\u65b9\u6cd5\u3001\u9759\u6001\u4ee3\u7801\u5757\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001\u5185\u90e8\u7c7b<\/span>\uff0c<\/strong><\/span><\/div>\n
<\/span> \u5305\u62ec\u4e0d\u80fd\u4f7f\u7528\u975e\u9759\u6001\u5185\u90e8\u7c7b\u5b9a\u4e49\u53d8\u91cf\u3001\u521b\u5efa\u5b9e\u4f8b\u3002<\/strong><\/span><\/div>\n
<\/span>v.\u6210\u5458\u53d8\u91cf\u8bbf\u95ee\u8981\u70b9\uff1a<\/strong><\/span><\/div>\n
<\/span>\n<\/span>1.\u5185\u90e8\u7c7b\u91cc\u65b9\u6cd5\u7684\u5c40\u90e8\u53d8\u91cf\uff1a\u53d8\u91cf\u540d<\/strong><\/span><\/div>\n
<\/span>2.\u5185\u90e8\u7c7b\u5c5e\u6027\uff1athis\u53d8\u91cf\u540d<\/strong><\/span><\/div>\n
<\/span>3.\u5916\u90e8\u7c7b\u5c5e\u6027\uff1a\u5916\u90e8\u7c7b\u540d.this.\u53d8\u91cf\u540d<\/strong><\/span><\/div>\n
<\/span>vi.\u5185\u90e8\u7c7b\u7684\u8bbf\u95ee\uff1a<\/strong><\/span><\/div>\n
<\/span>1.\u5916\u90e8\u7c7b\u4e2d\u5b9a\u4e49\u5185\u90e8\u7c7b\uff1anew innerClass();<\/strong><\/span><\/div>\n
<\/span>2.\u5916\u90e8\u7c7b\u4ee5\u5916\u7684\u5730\u65b9\u4f7f\u7528\u975e\u9759\u6001\u5185\u90e8\u7c7b\uff1a<\/strong><\/span><\/div>\n
<\/span>Outer.inner varname=OuterObject.new inner();<\/strong><\/span><\/div>\n
<\/span>eg.<\/strong><\/span><\/div>\n
<\/span>Face.Node nose=new Face().new Nose();<\/strong><\/span><\/div>\n
<\/span>\u6216\u8005\uff1a<\/strong><\/span><\/div>\n
<\/span>Face f2 =new Face();<\/strong><\/span><\/div>\n
<\/div>\n
<\/div>\n
<\/span>Face.Nose nose2=f2.new Nose();<\/strong><\/span><\/div>\n
<\/span>b)\u9759\u6001\u5185\u90e8\u7c7b<\/strong><\/span><\/div>\n
<\/span>i.\u5b9a\u4e49\u65b9\u5f0f\uff1a<\/strong><\/span><\/div>\n
<\/span>static class ClassName{\u7c7b\u4f53}<\/strong><\/span><\/div>\n
<\/span>ii.\u4f7f\u7528\u8981\u70b9<\/strong><\/span><\/div>\n
<\/span>1.\u5f53\u4e00\u4e2a\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\u5b58\u5728\u3002\u5e76\u4e0d\u4e00\u5b9a\u5b58\u5728\u5bf9\u5e94\u7684\u5916\u90e8\u7c7b\u5bf9\u8c61<\/span>\u3002\u56e0\u6b64\uff0c<\/strong><\/span><\/div>\n
<\/span> \u9759\u6001\u5185\u90e8\u7c7b\u7684\u5b9e\u4f8b\u65b9\u6cd5\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u5b9e\u4f8b\u65b9\u6cd5\u3002<\/strong><\/span><\/div>\n
<\/span>2.\u9759\u6001\u5185\u90e8\u7c7b\u770b\u505a\u5916\u90e8\u7c7b\u7684\u4e00\u4e2a\u9759\u6001\u6210\u5458<\/span>\u3002\u56e0\u6b64\uff0c\u5916\u90e8\u7c7b\u7684\u65b9\u6cd5\u4e2d\u53ef\u4ee5\u901a\u8fc7\uff1a<\/strong><\/span><\/div>\n
<\/span>\u9759\u6001\u5185\u90e8\u7c7b.\u540d\u5b57\u8bbf\u95ee\u9759\u6001\u5185\u90e8\u7c7b\u7684\u9759\u6001\u6210\u5458\u3002\u901a\u8fc7New\u9759\u6001\u5185\u90e8\u7c7b()<\/strong><\/span><\/div>\n
<\/span>\u8bbf\u95ee\u9759\u6001\u5185\u90e8\u7c7b\u7684\u5b9e\u4f8b\u3002<\/strong><\/span><\/div>\n
<\/span>3.\u5728\u5916\u90e8\u7c7b\u7684\u5916\u9762\u521b\u5efa\u9759\u6001\u5185\u90e8\u7c7b\uff1a<\/strong><\/span><\/div>\n
<\/span> Face.TestStaticInner aInner=new Face.TestStaticInner();<\/strong><\/span><\/div>\n
2\u3001\u533f\u540d\u5185\u90e8\u7c7b\uff08\u9002\u7528\u90a3\u79cd\u53ea\u9700\u8981\u4f7f\u7528\u4e00\u6b21\u7684\u7c7b\u3002\uff09<\/strong><\/span><\/div>\n
<\/span>\u8bed\u6cd5\uff1a<\/strong><\/span><\/div>\n
<\/span>new \u7236\u7c7b\u6784\u9020\u5668(\u5b9e\u53c2\u7c7b\u8868)\u5b9e\u73b0\u63a5\u53e3(){<\/strong><\/span><\/div>\n
<\/span>\/\/\u533f\u540d\u5185\u90e8\u7c7b\u7c7b\u4f53<\/strong><\/span><\/div>\n
}<\/strong><\/span><\/div>\n
3\u3001\u5c40\u90e8\u5185\u90e8\u7c7b\uff1a\u5b9a\u4e49\u5728\u65b9\u6cd5\u5185\u90e8\u3002\u4f5c\u7528\u4e8e\u53ea\u9650\u4e8e\u672c\u65b9\u6cd5\u3002\u7528\u7684\u5f88\u5c11<\/strong><\/span><\/div>\n <\/div>\n <\/div>","orderid":"0","title":"java\u67e5\u6f0f\u8865\u7f3a\uff08\u4e09\uff09","smalltitle":"","mid":"0","fname":"Hdfs","special_id":"0","bak_id":"0","info":"0","hits":"484","pages":"1","comments":"0","posttime":"2019-05-15 00:20:26","list":"1557850826","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"java<\/A> \u67e5\u6f0f<\/A> \u8865\u7f3a<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";s:4:\"head\";s:0:\"\";}","target":"0","ip":"47.106.78.186","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":" instanceof \uff1a\u5982 \uff1aAnimal d = new Dog();if(d instanceof Dog)\/\/\u5982\u679cd\u662fDog\u7684\u5b9e\u4f8b{d.voice;}\u4e3a\u4ec0\u4e48\u9700\u8981\u62bd\u8c61\u7c7b\uff1f\u5982\u4f55\u5b9a\u4e49\u62bd\u8c61\u7c7b\uff1f\u662f\u4e00\u79cd\u6a21\u677f\u6a21\u5f0f\u3002\u62bd\u8c61\u7c7b\u4e3a\u6240\u6709\u5b50\u7c7b\u63d0\u4f9b\u4e86\u4e00\u4e2a\u901a\u7528\u6a21\u677f\uff0c\u5b50\u7c7b\u53ef\u4ee5\u5728\u8fd9\u4e2a\u6a21\u677f\u57fa\u7840\u4e0a\u8fdb\u884c\u6269\u5c55\u3002\u901a\u8fc7..","lastview":"1714589248","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}