JAVA ÀíÂÛ×ܽá
Ò».±àд¹¹ÔìÆ÷µÄÓÐЧ׼Ôò£º Óþ¡¿ÉÄܼòµ¥µÄ·½·¨Ê¹¶ÔÏó½øÈëÕý³£×´Ì¬£¬Èç¹û¿ÉÒԵĻ°£¬±ÜÃâµ÷ÓÃÆäËû·½·¨¡£ÔÚ¹¹ÔìÆ÷ÄÚΨһÄܹ»°²È«µ÷ÓõÄÄÇЩ·½·¨ÊÇ»ùÀàÖеÄfinal·½·¨£¨Ò²ÊÊÓÃÓÚprivate·½·¨£¬ËüÃÇ×Ô¶¯ÊôÓÚfinal·½·¨£©¡£ ¶þ.Óü̳нøÐÐÉè¼ÆµÄ×¼Ôò£º Óü̳бí´ïÐÐΪ¼äµÄ²îÒ죬²¢ÓÃ×ֶαí´ï״̬Éϵı仯¡£ 1: class Actor {// ÄÐÑÝÔ±
2: public void act() {}
3: }
4:
5: class HappyActor extends Actor{//¸ßÐ˵ÄÄÐÑÝÔ±
6: public void act() {System.out.println("HappyActor");}
7: }
8:
9: class SadActor extends Actor{//±¯É˵ÄÄÐÑÝÔ±
10: @Override
11: public void act() {System.out.println("SadActor");}
12: }
13:
14: class Stage {//Îę̀
15: private Actor actor = new HappyActor();
16: public void change(){actor= new SadActor();}
17: public void PerformPlay(){actor.act();}
18: }
19: public class Transmogrify {
20:
21: /**
22: * Stage¶ÔÏó°üº¬Ò»¸öActor µÄÒýÓ㬶øActor±»³õʼ»¯ÎªHappyActor¶ÔÏó£¬
23: * ÕâÒâζ×ÅPerformPlay()»á²úÉúijÖÖÌØÊâÐÐΪ¡£
24: * ¼ÈÈ»ÒýÓÃÔÚÔËÐÐʱ¿ÉÒÔÓëÁíÒ»¸ö²»Í¬µÄ¶ÔÏóÖØаó¶¨ÆðÀ´£¬
25: * ËùÒÔSadActor¶ÔÏóµÄÒýÓÿÉÒÔÔÚActorÖб»Ìæ´ú£¬È»ºóÓÉPerformPlay()²úÉúµÄÐÐΪҲËæÖ®¸Ä±ä¡£
26: * ÕâÑùÒ»À´£¬ÎÒÃÇÔÚÔËÐÐÆÚ¼ä»ñµÃÁ˶¯Ì¬µÄÁé»îÐÔ£¨ÕâÒ²³Æ×÷"״̬ģʽ"£©
27: * @param args
28: */
29: public static void main(String[] args) {
30: Stage stage = new Stage();
31: stage.PerformPlay();
32: stage.change();
33: stage.PerformPlay();
34: }
35:
36: }/*Output:
37: HappyActor
38: SadActor*///:~
39:
Ïà¹ØÎĵµ£º
×¢Ò⣬Çë²»Òª±»ÎÒÎóµ¼£¬ÎÒûÓп´ÆäËû×ÊÁÏ£¬ÕâÊÇÎÒ×Ô¼º·ÖÎöµÄ£¬ÓÐЩ¿ÉÄÜÊDz»¶ÔµÄ
"DestroyJavaVM" prio=6 tid=0x00316800 nid=0x448 waiting on condition [0x00000000
..0x00a0fd4c]
java.lang.Thread.State: RUNNABLE
"Thread-1" prio=6 tid=0x02f85000 nid=0xd18 waiting for m ......
³ý °Ë¸ö»ù±¾ÀàÐÍ£¨Long ,short,int ,float,double,char,byte,boolean£©Í⣬ÆäËûµÄÊý¾ÝÀàÐͶ¼±»³ÆΪ“ÒýÓÃÀàÐÍ”£¬Ò²¼´£ºObject¡£ObjectµÄ²Ù×÷È«ÊÇͨ¹ý¶ÔÏóµÄÒýÓã¨Object references£©£¬ÒýÓÿÉÒÔÀí½âΪָÕ룬ÈÝÒ×ÈÃÈ˶ÔÓ¦µ½C£«£«µÄ´«Ö·ÉÏÃæÈ¥¡£ËùÒÔ£¬´ó¼ÒҪעÒâඣ¡javaÀïÃæËä˵ûָÕ룬Æäʵȴ²»È»¡£ ......
ʱ¼ä¹ýµÄÕæ¿ì£¬²»Öª²»¾õÀ´µ½´«ÖDz¥¿ÍÒѾһ¸ö¶àÔÂÁË£¬ÕâÒ»¸öÔÂÖ÷ҪѧϰÁËJava»ù´¡²¿·Ö£¬ËäȻÿÌ춼ÊÇÇôúÂëµ½ÍíÉÏ1¡¢2µã²Å˯¾õ£¬µ«ÊÇ»¹ÊǸоõʱ¼ä²»¹»Óã¬ÒòΪÐèҪѧϰ¹®¹ÌµÄ¶«Î÷Ì«¶àÌ«¶àÁË£¬×ܸоõÕÆÎյIJ»¹»ºÃ£¬ÕâÒ»¸öÔ¹ýµÄºÜÀÛµ«Ò²ºÜ³äʵ¡£
Õ⼸Ì쿪ʼ ......
ʵÑéÒªÇó£º
1.±àд»ùÓÚTCPÐÒéµÄͨÐųÌÐò£¬°üÀ¨ServerÓëClientÁ½¸ö²¿·Ö¡£ÊµÏÖ»ØÉù³ÌÐò£º¼´¿Í»§¶Ë·¢ËÍÏûÏ¢£¬·þÎñÆ÷¶Ë½«ÊÕµ½µÄÏûÏ¢ÔÑù»áË͸ø¿Í»§¶Ë¡£
2.ÔÚµ¥»úÉÏÔËÐÐËüÃÇ£¬ÑéÖ¤ÆäͨÐŽá¹û£»
3.ÔÚ¶à»úÉÏÔËÐÐËüÃÇ£¬ÑéÖ¤ÆäͨÐŽá¹û£»£¨ChatServerÖ»ÐèÔËÐÐÔÚһ̨Ö÷»úÉÏ£¬ChatClient¿ÉÔÚÆäËüÖ÷»úÉÏÔËÐУ¨ÒªÖªµÀChatServerËùÔ ......