Java鍙嶅皠鏈哄埗
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java鍙嶅皠鏈哄埗相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/system' title='system'>system
褰撶▼搴忚繍琛屾椂锛屽厑璁告敼鍙樼▼搴忕粨鏋勬垨鍙橀噺绫诲瀷锛岃繖绉嶈瑷€绉颁负鍔ㄦ€佽瑷€銆傛垜浠涓簀ava骞朵笉鏄姩鎬佽瑷€锛屼絾鏄畠鍗存湁涓€涓潪甯哥獊鍑虹殑鍔ㄦ€佺浉鍏虫満鍒讹紝淇楃О锛氬弽灏勩€?br/> IT琛屼笟閲岃繖涔堣锛屾病鏈夊弽灏勪篃灏辨病鏈夋鏋讹紝鐜版湁鐨勬鏋堕兘鏄互鍙嶅皠涓哄熀纭€銆傚湪瀹為檯椤圭洰寮€鍙戜腑锛岀敤鐨勬渶澶氱殑鏄鏋讹紝濉殑鏈€澶氱殑鏄被锛屽弽灏勮繖涓€姒傚康灏辨槸灏嗘鏋跺拰绫绘弶鍦ㄤ竴璧风殑璋冨拰鍓傘€傛墍浠ワ紝鍙嶅皠鎵嶆槸鎺ヨЕ椤圭洰寮€鍙戠殑鏁查棬鐮栵紒
涓€銆丆lass绫?br/>浠€涔堟槸Class绫伙紵
鍦ㄩ潰鍚戝璞$殑涓栫晫閲岋紝涓囦簨涓囩墿鐨嗘槸瀵硅薄銆傝€屽湪java璇█涓紝static淇グ鐨勪笢瑗夸笉鏄璞★紝浣嗘槸瀹冨睘浜庣被銆傛櫘閫氱殑鏁版嵁绫诲瀷涓嶆槸瀵硅薄锛屼緥濡傦細int a = 5;
瀹冧笉鏄潰鍚戝璞★紝浣嗘槸瀹冩湁鍏跺寘瑁呯被 Integer 鎴栬€呭垎瑁呯被鏉ュ讥琛ヤ簡瀹冦€傞櫎浜嗕互涓婁袱绉嶄笉鏄潰鍚戝璞★紝鍏朵綑鐨勫寘鎷被涔熸湁瀹冪殑闈㈠悜瀵硅薄锛岀被鏄痡ava.lang.Class鐨勫疄渚嬪寲瀵硅薄锛堟敞鎰廋lass鏄ぇ鍐欙級銆備篃灏辨槸璇达細Class A{}
褰撴垜鍒涘缓浜咥绫伙紝閭d箞绫籄鏈韩灏辨槸涓€涓璞★紝璋佺殑瀵硅薄锛焜ava.lang.Class鐨勫疄渚嬪璞°€?br/> 閭d箞杩欎釜瀵硅薄鍙堣鎬庝箞琛ㄧず鍛紵
鎴戜滑鍏堢湅涓€涓嬩笅闈㈣繖娈典唬鐮侊細
1 2 3 4 | public class Demo(){ F f= new F(); } class F{} |
杩欓噷鐨凢鐨勫疄渚嬪寲瀵硅薄灏卞彲浠ョ敤f琛ㄨ揪鍑烘潵銆傚悓鐞咶绫讳篃鏄竴涓疄渚嬪寲瀵硅薄锛孋lass绫荤殑瀹炰緥鍖栧璞°€傛垜浠彲浠ョ悊瑙d负浠讳綍涓€涓被閮芥槸Class绫荤殑瀹炰緥鍖栧璞★紝杩欑瀹炰緥鍖栧璞℃湁涓夌琛ㄧず鏂规硶锛?/p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class Demo(){ F f= new F(); //绗竴绉嶈〃杈炬柟寮?/code> Class c1=F. class ; //杩欑琛ㄨ揪鏂瑰紡鍚屾椂涔熷憡璇変簡鎴戜滑浠讳綍涓€涓被閮芥湁涓€涓殣鍚殑闈欐€佹垚鍛樺彉閲廲lass //绗簩绉嶈〃杈炬柟寮?/code> Class c2=f.getClass(); //杩欑琛ㄨ揪鏂瑰紡鍦ㄥ凡鐭ヤ簡璇ョ被鐨勫璞$殑鎯呭喌涓嬮€氳繃getClass鏂规硶鑾峰彇 //绗笁绉嶈〃杈炬柟寮?/code> Class c3 = null ; try { c3 = Class.forName( "com.text.F" ); //绫荤殑鍏ㄧО } catch (ClassNotFoundException e) { e.printStackTrace(); } } class F{} |
浠ヤ笂涓夌琛ㄨ揪鏂瑰紡锛宑1,c2,c3閮借〃绀轰簡F绫荤殑绫荤被鍨嬶紝涔熷氨鏄畼鏂硅В閲婄殑Class Type銆?br/> 閭d箞闂鏉ヤ簡锛?/p>
1 | System.out.println(c1 == c2)? or System.out.println(c1 == c3)? |
绛旀鏄偗瀹氱殑锛岃繑鍥炲€间负ture銆傝繖琛ㄦ槑涓嶈c1 or c2 or c3閮戒唬琛ㄤ簡F绫荤殑绫荤被鍨嬶紝涔熷氨鏄涓€涓被鍙彲鑳芥槸Class绫荤殑涓€涓疄渚嬪璞°€?br/> 鐞嗚В浜咰lass鐨勬蹇碉紝鎴戜滑涔熷彲浠ラ€氳繃绫荤殑绫荤被鍨嬪垱寤鸿绫荤殑瀵硅薄瀹炰緥锛岀敤c1 or c2 or c3鐨刵ewInstance()鏂规硶锛?/p>
1 2 3 4 5 6 7 8 9 10 11 12 13 | Public class Demo1{ try { Foo foo = (Foo)c1.newInstance(); //foo灏辫〃绀篎绫荤殑瀹炰緥鍖栧璞?/code> foo.print(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }} class F{ void print(){ } } |
杩欓噷闇€瑕佹敞鎰忕殑鏄紝c1鏄疐绫荤殑绫荤被鍨嬶紝鍒涘缓鍑烘潵鐨勫氨鏄疐绫荤殑瀵硅薄銆傚鏋渁鏄疉绫荤殑绫荤被鍨嬶紝閭d箞鍒涘缓鍑烘潵鐨勫璞′篃搴旇涓庝箣瀵瑰簲锛屽睘浜嶢绫荤殑瀵硅薄銆?/p>
浜屻€佹柟娉曠殑鍙嶅皠
Class绫绘湁涓€涓渶绠€鍗曠殑鏂规硶锛実etName()锛?/p>
1 2 3 4 5 6 7 8 9 10 11 | public class Demo2 { public static void main(String[] args) { Class c1 = int . class ; //int 鐨勭被绫诲瀷 Class c2 = String. class ; //String绫荤殑绫荤被鍨?/code> Class c3 = void . class ; System.out.println(c1.getName()); System.out.println(c2.getName()); System.out.println(c2.getSimpleName()); System.out.println(c3.getName()); } } |
鏈殑鏁版嵁绫诲瀷浠ュ強void鍏抽敭瀛楅兘鏄瓨鍦ㄧ被绫诲瀷鐨勩€?/span>
妗堜緥锛?/p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | public class ClassUtil { public static void printClassMethodMessage(Object obj){ //瑕佽幏鍙栫被鐨勪俊鎭€嬨€嬮鍏堟垜浠鑾峰彇绫荤殑绫荤被鍨?/code> Class c = obj.getClass(); //鎴戜滑鐭ラ亾Object绫绘槸涓€鍒囩被鐨勭埗绫伙紝鎵€浠ユ垜浠紶閫掔殑鏄摢涓瓙绫荤殑瀵硅薄锛宑灏辨槸璇ュ瓙绫荤殑绫荤被鍨嬨€?/code> //鎺ヤ笅鏉ユ垜浠鑾峰彇绫荤殑鍚嶇О System.out.println( "绫荤殑鍚嶇О鏄?" +c.getName()); /* *鎴戜滑鐭ラ亾锛屼竾浜嬩竾鐗╅兘鏄璞★紝鏂规硶涔熸槸瀵硅薄锛屾槸璋佺殑瀵硅薄鍛紵 * 鍦╦ava閲岄潰锛屾柟娉曟槸Method绫荤殑瀵硅薄 *涓€涓垚鍛樻柟娉曞氨鏄竴涓狹ethod鐨勫璞★紝閭d箞Method灏卞皝瑁呬簡瀵硅繖涓垚鍛?/code> *鏂规硶鐨勬搷浣?/code> */ //濡傛灉鎴戜滑瑕佽幏寰楁墍鏈夌殑鏂规硶锛屽彲浠ョ敤getMethods()鏂规硶锛岃繖涓柟娉曡幏鍙栫殑鏄墍鏈夌殑Public鐨勫嚱鏁帮紝鍖呮嫭鐖剁被缁ф壙鑰屾潵鐨勩€傚鏋滄垜浠鑾峰彇鎵€鏈夎绫昏嚜宸卞0鏄庣殑鏂规硶锛屽氨鍙互鐢╣etDeclaredMethods()鏂规硶锛岃繖涓柟娉曟槸涓嶉棶璁块棶鏉冮檺鐨勩€?/code> Method[] ms = c.getMethods(); //c.getDeclaredMethods() //鎺ヤ笅鏉ユ垜浠嬁鍒拌繖浜涙柟娉曚箣鍚庡共浠€涔堬紵鎴戜滑灏卞彲浠ヨ幏鍙栬繖浜涙柟娉曠殑淇℃伅锛屾瘮濡傛柟娉曠殑鍚嶅瓧銆?/code> //棣栧厛鎴戜滑瑕佸惊鐜亶鍘嗚繖浜涙柟娉?/code> for ( int i = 0 ; i < ms.length;i++){ //鐒跺悗鍙互寰楀埌鏂规硶鐨勮繑鍥炲€肩被鍨嬬殑绫荤被鍨?/code> Class returnType = ms[i].getReturnType(); //寰楀埌鏂规硶鐨勮繑鍥炲€肩被鍨嬬殑鍚嶅瓧 System.out.print(returnType.getName()+ " " ); //寰楀埌鏂规硶鐨勫悕绉?/code> System.out.print(ms[i].getName()+ "(" ); //鑾峰彇鍙傛暟绫诲瀷--->寰楀埌鐨勬槸鍙傛暟鍒楄〃鐨勭被鍨嬬殑绫荤被鍨?/code> Class[] paramTypes = ms[i].getParameterTypes(); for (Class class1 : paramTypes) { System.out.print(class1.getName()+ "," ); } System.out.println( ")" ); } } } |
鎬荤粨鎬濊矾锛?br/> 閫氳繃鏂规硶鐨勫弽灏勫緱鍒拌绫荤殑鍚嶇О姝ラ锛?br/> 1.鑾峰彇璇ョ被鐨勭被绫诲瀷
2.閫氳繃绫荤被鍨嬭幏鍙栫被鐨勬柟娉曪紙getMethods()锛?br/> 3.寰幆閬嶅巻鎵€鑾峰彇鍒扮殑鏂规硶
4.閫氳繃杩欎簺鏂规硶鐨刧etReturnType()寰楀埌杩斿洖鍊肩被鍨嬬殑绫荤被鍨嬶紝鍙堥€氳繃璇ョ被绫诲瀷寰楀埌杩斿洖鍊肩被鍨嬬殑鍚嶅瓧
5.getName()寰楀埌鏂规硶鐨勫悕绉帮紝getParameterTypes()鑾峰彇杩欎釜鏂规硶閲岄潰鐨勫弬鏁扮被鍨嬬殑绫荤被鍨嬨€?/p>
涓夈€佹垚鍛樺彉閲忕殑鍙嶅皠
棣栧厛鎴戜滑闇€瑕佽璇嗗埌鎴愬憳鍙橀噺涔熸槸瀵硅薄锛屾槸java.lang.reflect.Field绫荤殑瀵硅薄锛岄偅涔堜篃灏辨槸璇碏ield绫诲皝瑁呬簡鍏充簬鎴愬憳鍙橀噺鐨勬搷浣溿€傛棦鐒跺畠灏佽浜嗘垚鍛樺彉閲忥紝鎴戜滑鍙堣濡備綍鑾峰彇杩欎簺鎴愬憳鍙橀噺鍛紵瀹冩湁杩欎箞涓€涓柟娉曪細
1 2 3 4 5 | public class ClassUtil { public static void printFieldMessage(Object obj){ Class c = obj.getClass(); //Field[] fs = c.getFields(); } |
杩欓噷鐨刧etFields()鏂规硶鑾峰彇鐨勬墍鏈夌殑public鐨勬垚鍛樺彉閲忕殑淇℃伅銆傚拰鏂规硶鐨勫弽灏勯偅閲宲ublic鐨勬垚鍛樺彉閲忥紝涔熸湁涓€涓幏鍙栨墍鏈夎嚜宸卞0鏄庣殑鎴愬憳鍙橀噺鐨勪俊鎭細Field[] fs = c.getDeclaredFields();
鎴戜滑寰楀埌瀹冧箣鍚庯紝鍙互杩涜閬嶅巻锛堟棦鐒跺皝瑁呬簡Field鐨勪俊鎭紝閭d箞鎴戜滑灏卞彲浠ュ緱鍒癋ield绫诲瀷锛?/p>
1 2 3 4 5 6 7 8 | for (Field field : fs) { //寰楀埌鎴愬憳鍙橀噺鐨勭被鍨嬬殑绫荤被鍨?/code> Class fieldType = field.getType(); String typeName = fieldType.getName(); //寰楀埌鎴愬憳鍙橀噺鐨勫悕绉?/code> String fieldName = field.getName(); System.out.println(typeName+ " " +fieldName); } |
鍥涖€佹瀯閫犲嚱鏁扮殑鍙嶅皠
涓嶈鏄柟娉曠殑鍙嶅皠銆佹垚鍛樺彉閲忕殑鍙嶅皠銆佹瀯閫犲嚱鏁扮殑鍙嶅皠锛屾垜浠彧闇€瑕佺煡閬擄細瑕佹兂鑾峰彇绫荤殑淇℃伅锛岄鍏堝緱鑾峰彇绫荤殑绫荤被鍨嬨€?/p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public static void printConMessage(Object obj){ Class c = obj.getClass(); /* * 棣栧厛鏋勯€犲嚱鏁颁篃鏄璞★紝鏄痡ava.lang.Constructor绫荤殑瀵硅薄 * 涔熷氨鏄痡ava.lang. Constructor涓皝瑁呬簡鏋勯€犲嚱鏁扮殑淇℃伅 * 鍜屽墠闈㈣鍒扮殑涓€鏍凤紝瀹冧篃鏈変袱涓柟娉曪細 * getConstructors()鏂规硶鑾峰彇鎵€鏈夌殑public鐨勬瀯閫犲嚱鏁?/code> * getDeclaredConstructors()鏂规硶寰楀埌鎵€鏈夌殑鑷繁澹版槑鐨勬瀯閫犲嚱鏁?/code> */ //Constructor[] cs = c.getConstructors(); Constructor[] cs = c.getDeclaredConstructors(); for (Constructor constructor : cs) { //鎴戜滑鐭ラ亾鏋勯€犳柟娉曟槸娌℃湁杩斿洖鍊肩被鍨嬬殑锛屼絾鏄垜浠彲浠ワ細 System.out.print(constructor.getName()+ "(" ); //鑾峰彇鏋勯€犲嚱鏁扮殑鍙傛暟鍒楄〃銆嬨€嬪緱鍒扮殑鏄弬鏁板垪琛ㄧ殑绫荤被鍨?/code> Class[] paramTypes = constructor.getParameterTypes(); for (Class class1 : paramTypes) { System.out.print(class1.getName()+ "," ); } System.out.println( ")" ); } } |
浜斻€丆lass绫荤殑鍔ㄦ€佸姞杞界被
濡備綍鍔ㄦ€佸姞杞戒竴涓被鍛紵
棣栧厛鎴戜滑闇€瑕佸尯鍒嗕粈涔堟槸鍔ㄦ€佸姞杞斤紵浠€涔堟槸闈欐€佸姞杞斤紵鎴戜滑鏅亶璁や负缂栬瘧鏃跺埢鍔犺浇鐨勭被鏄潤鎬佸姞杞界被锛岃繍琛屾椂鍒诲姞杞界殑绫绘槸鍔ㄦ€佸姞杞界被銆傛垜浠妇涓€涓緥瀛愶細
1 2 3 4 5 6 7 8 9 10 11 12 | Class A{ Public static void main(String[] args){ if ( "B" .equal(args[ 0 ])){ B b= new B(); b.start(); } if ( "C" .equal(args[ 0 ])){ C c= new C(); C.start(); } } } |
涓婇潰杩欎竴娈典唬鐮侊紝褰撴垜浠湪鐢╡clipse鎴栬€卪yeclipse鐨勬椂鍊欐垜浠苟涓嶅叧蹇冩槸鍚﹁兘澶熼€氳繃缂栬瘧锛屽綋鎴戜滑鐩存帴鍦╟md浣跨敤javac璁块棶A.java绫荤殑鏃跺€欙紝灏变細鎶涘嚭闂:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | A.java锛?/code> B b= new B(); 绗﹀彿: 绫籅 浣嶇疆锛?绫籄 A.java锛?/code> B b= new B(); 绗﹀彿: 绫籅 浣嶇疆锛?绫籄 A.java锛?/code> C c= new C(); 绗﹀彿: 绫籆 浣嶇疆锛?绫籄 A.java锛?/code> C c= new C(); 绗﹀彿: 绫籆 浣嶇疆锛?绫籄 4 涓敊璇?/code> |
鎴栬鎴戜滑鐞嗘墍褰撶劧鐨勮涓鸿繖鏍峰簲璇ユ槸閿欙紝绫籅鏍规湰灏变笉瀛樺湪銆備絾鏄鏋滄垜浠鎬濊€冧竴涓嬶紝灏变細鍙戠幇B涓€瀹氱敤鍚楋紵涓嶄竴瀹氥€侰涓€瀹氱敤鍚楋紵涔熶笉涓€瀹氥€傞偅涔堝ソ锛岀幇鍦ㄦ垜浠氨璁〣绫诲瓨鍦?/p>
1 2 3 4 5 | Class B{ Public static void start(){ System.out.print( "B...satrt" ); } } |
鐜板湪鎴戜滑灏卞厛 javac B.class,璁〣绫诲厛寮€濮嬬紪璇戙€傜劧鍚庡湪杩愯javac A.class銆傜粨鏋滄槸锛?/p>
1 2 3 4 5 6 7 8 9 | A.java锛?/code> C c= new C(); 绗﹀彿: 绫籆 浣嶇疆锛?绫籄 A.java锛?/code> C c= new C(); 绗﹀彿: 绫籆 浣嶇疆锛?绫籄 2 涓敊璇?/code> |
鎴戜滑鍐嶆兂锛岃繖涓▼搴忔湁浠€涔堥棶棰樸€傚鏋滀綘璇存病鏈変粈涔堥棶棰橈紵C绫绘湰鏉ュ氨涓嶅瓨鍦ㄥ晩锛侀偅涔堥棶棰樻潵浜咮绫诲凡缁忓瓨鍦ㄤ簡锛屽亣璁炬垜鐜板湪灏辨兂鐢˙锛屾垜浠繖涓▼搴忕敤寰椾簡鍚楋紵绛旀鏄偗瀹氱殑锛岀敤涓嶄簡銆傞偅鐢ㄤ笉浜嗙殑鍘熷洜鏄粈涔堬紵鍥犱负鎴戜滑杩欎釜绋嬪簭鏄仛鐨勭被鐨勯潤鎬佸姞杞斤紝涔熷氨鏄new鍒涘缓瀵硅薄鏄潤鎬佸姞杞界被锛屽湪缂栬瘧鏃跺埢灏遍渶瑕佸姞杞芥墍鏈夌殑锛屽彲鑳戒娇鐢ㄥ埌鐨勭被銆傛墍浠ヤ笉绠′綘鐢ㄤ笉鐢ㄨ繖涓被銆?br/> 鐜板湪B绫绘槸瀛樺湪鐨勶紝浣嗘槸鎴戜滑杩欎釜绋嬪簭浠嶇劧鐢ㄤ笉浜嗭紝鍥犱负浼氫竴鐩存姤C绫绘湁闂锛屾墍浠绫绘垜涔熺敤涓嶄簡銆傞偅涔堝湪瀹為檯搴旂敤褰撲腑锛屾垜浠偗瀹氶渶瑕佸鏋淏绫诲瓨鍦紝B绫绘垜灏辫兘鐢紝褰撶敤C绫荤殑鏃跺€欙紝浣犲啀鍛婅瘔鎴戦敊浜嗐€傚鏋滆灏嗘潵浣犳湁100涓被锛屽彧瑕佸叾涓竴涓被鍑虹幇闂锛屽叾瀹?9涓被浣犻兘鐢ㄤ笉浜嗐€傛墍浠ヨ繖骞朵笉鏄垜浠兂瑕佺殑銆?br/> 鎴戜滑鎯宠鐨勫氨鏄垜鐢ㄩ偅涓被灏卞姞杞介偅涓被锛屼篃灏辨槸甯歌鐨?em>杩愯鏃跺埢鍔犺浇锛屽姩鎬佸姞杞界被
銆傚浣曞疄鐜板姩鎬佸姞杞界被鍛紵鎴戜滑鍙互寤鸿繖涔堜竴涓被锛?/p>1 2 3 4 5 6 7 8 9 10 11 | Class All{ Public static void start(){ try { Class cl= Class.forName(args[ 0 ]); //閫氳繃绫荤被鍨嬶紝鍒涘缓璇ョ被鐨勫璞?/code> cl.newInstance(); } catch (Exception e){ e.printStackTrace(); } } } |
鍓嶉潰鎴戜滑鍦ㄥ垎鏋怌lass瀹炰緥鍖栧璞$殑鏂瑰紡鐨勬椂鍊欙紝Class.forName(鈥滅被鐨勫叏绉扳€?锛屽畠涓嶄粎浠呰〃绀轰簡绫荤殑绫荤被鍨嬶紝杩樿〃绀轰簡鍔ㄦ€佸姞杞界被銆傚綋鎴戜滑javac All.java鐨勬椂鍊欙紝瀹冧笉浼氭姤浠讳綍閿欒锛屼篃灏辨槸璇村湪缂栬瘧鐨勬椂鍊欐槸娌℃湁閿欒鐨勩€傚彧鏈夊綋鎴戜滑鍏蜂綋鐢ㄦ煇涓被鐨勬椂鍊欙紝閭d釜绫讳笉瀛樺湪锛屽畠鎵嶄細鎶ラ敊銆?br/> 濡傛灉鍔犺浇鐨勭被鏄疊绫伙紝灏遍渶瑕侊細
1 | B bt = (B) cl.newInstance(); |
涓囦竴鍔犺浇鐨勬槸C绫诲憿锛屽彲浠ユ敼鎴?/p>
1 | C ct = (C) cl.newInstance(); |
浣嗘槸濡傛灉鎴戞兂鐢ㄥ緢澶氱殑绫绘垨鑰呭姞杞藉緢澶氱殑绫伙紝璇ユ€庝箞鍔烇紵鎴戜滑鍙互缁熶竴涓€涓爣鍑嗭紝涓嶈C绫昏繕鏄疊绫绘垨鑰呭叾浠栫殑绫伙紝姣斿瀹氫箟涓€涓爣鍑?/p>
1 | Stand s = (Stand) cl.newInstance(); |
鍙B绫诲拰C绫婚兘鏄繖涓爣鍑嗙殑灏辫浜嗐€?/p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Class All{ Public static void start(){ try { Class cl= Class.forName(args[ 0 ]); //閫氳繃绫荤被鍨嬶紝鍒涘缓璇ョ被鐨勫璞?/code> Stand s = (Stand) cl.newInstance(); s.start(); } catch (Exception e){ e.printStackTrace(); } } } interface Stand { Public void start(); } |
鐜板湪濡傛灉鎴戞兂瑕佺敤B绫伙紝鎴戜滑鍙渶瑕侊細
1 2 3 4 5 | Class B implements Stand{ Public void start(){ System.out.print( "B...satrt" ); } } |
鍔犺浇B绫?缂栬瘧杩愯銆?/p>
1 2 3 | javac B.java javac Stand.java java Stand B |
缁撴灉锛?/p>
1 | B...satrt |
濡傛灉浠ュ悗鎯崇敤鏌愪竴涓被锛屼笉闇€瑕侀噸鏂扮紪璇戯紝鍙渶瑕佸疄鐜拌繖涓爣鍑嗙殑鎺ュ彛鍗冲彲銆傚彧闇€瑕佸姩鎬佺殑鍔犺浇鏂扮殑涓滆タ灏辫浜嗐€?br/> 杩欏氨鏄?em>鍔ㄦ€佸姞杞界被
銆?/p>以上是关于Java鍙嶅皠鏈哄埗的主要内容,如果未能解决你的问题,请参考以下文章