Ç°ÃæÄÇÒ»´ó¶ÎÏŵ½ÎÒÁË¡­¡­
µÇ¼ | ÂÛ̳µ¼º½ -> »ªÐÂÏÊÊ -> ÐÄÇéÏÐÁÄ | ±¾Ìû¹²ÓÐ 2 Â¥£¬·Ö 1 Ò³, µ±Ç°ÏÔʾµÚ 1 Ò³ : ±¾ÌûÊ÷ÐÎÁбí : ˢР: ·µ»ØÉÏÒ»Ò³
×÷ÕߣºÐ¡ÑýÁØÁØ (µÈ¼¶£º?? - ÎÞ·¨ÎÞÌ죬·¢Ìû£º39476) ·¢±í£º2012-08-16 15:13:01¡¡ Â¥Ö÷¡¡ ¹Ø×¢´ËÌû
¡¾ÆäËü»°Ìâ¡¿ÇóÖúÒ»¶Îjava codeСµÜÄ¿Ç°¸Õ¸ÕÉÏÊÖjava, ¿´µ½think in javaÀïÓÐÕâÒ»¶Îcode£¬ÈçÏ£º //: reusing/SprinklerSystem.java // Composition for code reuse. class WaterSource { private String s; WaterSource() { System.out.println("WaterSource()"); s = "Constructed"; } public String toString() { return s; } } public class SprinklerSystem { private String valve1, valve2, valve3, valve4; private WaterSource source = new WaterSource(); private int i; private float f; public String toString() { return "valve1 = " + valve1 + " " + "valve2 = " + valve2 + " " + "valve3 = " + valve3 + " " + "valve4 = " + valve4 + "\n" + "i = " + i + " " + "f = " + f + " " + "source = " + source; } public static void main(String[] args) { SprinklerSystem sprinklers = new SprinklerSystem(); System.out.println(sprinklers); } } ¡¡ /* Output: WaterSource() valve1 = null valve2 = null valve3 = null valve4 = null i = 0 f = 0.0 source = Constructed *///: ʵÔÚ²»¶®ÎªÊ²Ã´×îºóoutputÀïµÄsource=Constructed. ÌصØÇ°À (more...)
Ç°ÃæÄÇÒ»´ó¶ÎÏŵ½ÎÒÁË¡­¡­
Ïë˵£¬²»ÊÇÎÊjavaÀ´×ÅÂð= =
ÿÌ춼Ҫ£ºË¢ÑÀ£¬Ï´Ô裬ÉÏ»ªÐ£¡


»¶Ó­À´µ½»ªÐÂÖÐÎÄÍø£¬Ó»Ô¾·¢ÌûÊÇÖ§³ÖÎÒÃǵÄ×îºÃ·½·¨!Ô­ÎÄ / ´«Í³°æ / WAP°æËùÓлظ´´ÓÕâÀïÕ¹¿ªÊÕÆðÁбí
×÷ÕߣºÐ¡ÑýÁØÁØ (µÈ¼¶£º?? - ÎÞ·¨ÎÞÌ죬·¢Ìû£º39476) ·¢±í£º2012-08-16 15:26:50¡¡ 2Â¥
²»ÖªµÀÓÐû½âÊͶÔSprinklerSystemÀàÀïÃ涨ÒåÁËsoureÕâÒ»±äÁ¿ private WaterSource source = new WaterSource(); Ò²¾ÍÊÇ˵source Õâ¸ö±äÁ¿ÊôÓÚWaterSourceÀà È»ºómain³ÌÐòÖÐSystem.out.println(sprinklers)»áµ÷Óà public String toString() { return "valve1 = " + valve1 + " " + "valve2 = " + valve2 + " " + "valve3 = " + valve3 + " " + "valve4 = " + valve4 + "\n" + "i = " + i + " " + "f = " + f + " " + "source = " + source; } ÕâÀïÃæ"source = " + source;ÕâÒ»¾äÓÖ»áµ÷ÓÃsourceÕâÒ»±äÁ¿£¨ÊôÓÚWaterSourceÀࣩÖÐµÄ public String toString() { return s; } ¶øsµÄ³õʼֵÊÇ Constructed
ÏÈËÍЩ·Ö¸øÄã~~~
»¶Ó­À´µ½»ªÐÂÖÐÎÄÍø£¬Ó»Ô¾·¢ÌûÊÇÖ§³ÖÎÒÃǵÄ×îºÃ·½·¨!Ô­ÎÄ / ´«Í³°æ / WAP°æËùÓлظ´´ÓÕâÀïÕ¹¿ªÊÕÆðÁбí
ÂÛ̳µ¼º½ -> »ªÐÂÏÊÊ -> ÐÄÇéÏÐÁÄ | ·µ»ØÉÏÒ»Ò³ | ±¾Ö÷Ìâ¹²ÓÐ 2 ƪÎÄÕ£¬·Ö 1 Ò³, µ±Ç°ÏÔʾµÚ 1 Ò³ | »Øµ½¶¥²¿
<<ʼҳ¡¡ [1]¡¡ Ä©Ò³>>

ÇëµÇ¼ºó»Ø¸´£ºÕʺŠ¡¡ ÃÜÂë ¡¡