javaÖй¹Ô캯ÊýµÄµ÷ÓÃ˳Ðò
µ±Ò»¸ö¸´ÔӵĶÔÏó±»¹¹Ôìʱ,ËüµÄ¹¹Ô캯Êý°´ÏÂÃæµÄ˳Ðò±»µ÷ÓÃ(that the order of constructor calls for a complex object is as follows)
1.Æä»ùÀà(base-class)µÄ¹¹Ô캯Êý±»µ÷ÓÃ,Õâ¸ö²½ÖèÒԵݹéµÄ·½Ê½Öظ´,ËùÒÔ×îµ×²ã(the root of hierarchy)µÄ¹¹Ô캯ÊýÊ×Ïȱ»Ö´ÐÐ,È»ºóÊÇËüÉÏÒ»²ãÅÉÉúÀà(the next-derived class)...Ö±µ½×²ãµÄÅÉÉúÀà(the most-derived class).
The base-class constructor is called. This step is repeated recursively such that the root of the hierarchy is constructed first, followed by the next-derived class, etc., until the most-derived class is reached.)
2.Èç¹ûÓаüº¬¹Øϵ(composition),ÄÇôËüµÄ³ÉÔ±¶ÔÏó°´ÕÕÉùÃ÷µÄ˳Ðò±»¹¹Ôì.
Member initializers are called in the order of declaration.
3.ÅÉÉúÀ๹Ô캯ÊýµÄÄÚÈÝ(body)±»Ö´ÐÐ.
The body of the derived-class constructor is called.
Ò»¸öʵÀý:
class Cake{
Cake(){System.out.println("Cake()");}
}
class Meal {
Meal() { System.out.println("Meal()"); }
}
class Bread {
Bread() { System.out.println("Bread()"); }
}
class Cheese {
Cheese() { System.out.println("Cheese()"); }
}
class Lettuce {
Lettuce() { System.out.println("Lettuce()"); }
}
class Lunch extends Meal {
Lunch() { System.out.println("Lunch()"); }
}
class PortableLunch extends Lunch {
//if make derived-class object as the menber of the base-class will lead a infinite
//loop and program will stop because of the memory consumed
//private Sandwich s=new Sandwich();
private Cake a=new Cake();
PortableLunch() {&n
Ïà¹ØÎĵµ£º
1£®toString£¨£©·½·¨
ObjectÀà¾ßÓÐÒ»¸ötoString()·½·¨£¬Äã´´½¨µÄÿ¸öÀ඼»á¼Ì³Ð¸Ã·½·¨¡£Ëü·µ»Ø¶ÔÏóµÄÒ»¸öString±íʾ£¬²¢ÇÒ¶ÔÓÚµ÷ÊԷdz£ÓаïÖú¡£È»¶ø¶ÔÓÚĬÈϵÄtoString()·½·¨ÍùÍù²»ÄÜÂú×ãÐèÇó£¬ÐèÒª¸²¸ÇÕâ¸ö·½·¨¡£
toString£¨£©·½·¨½«¶ÔÏóת»»Îª×Ö·û´®¡£¿´ÒÔÏ´úÂ룺
package sample;
class Villain {
&nb ......
µ¥Ôª²âÊÔ
1.
DBUnit
DBunitÊÇÒ»¸ö»ùÓÚjunitÀ©Õ¹µÄÊý¾Ý¿â²âÊÔ¿ò¼Ü¡£ËüÌṩÁË´óÁ¿µÄÀà¶ÔÓëÊý¾Ý¿âÏà¹ØµÄ²Ù×÷½øÐÐÁ˳éÏóºÍ·â×°¡£
2.MOckito
MockitoÊÇÒ»¸öÕë¶ÔJavaµÄmocking¿ò¼Ü¡£Äã¿ÉÒÔʹÓüò½àµÄAPI±àд³öƯÁÁµÄ²âÊÔ¡£
3.Hamcrest Matchers
Hamcrest ÊÇÒ»¸ö²âÊÔ¸¨Öú¹¤¾ß£¬ÌṩÁËÒ»Ì×ͨÓõÄÆ¥Åä·û Matcher£¬Áé»îʹÓÃÕâÐ ......
Java 7ÌṩÁËÒ»¸öÐÂAPI·ÃÎÊÎļþϵͳ£¬µ«³ý´ËÖ®Í⣬JSR 203(NIO.2)»¹°üº¬ÆäËüºÜ¶àÐÂÌØÐÔ£¬Õâ¸öа汾µÄÈ·ÐÂÔöÁ˺ܶà¸ÄÉÆI/O±à³ÌµÄÀ࣬±¾ÎĽ«»á½éÉÜÏÂÃæµÄÐÂÌØÐÔ£º
· SeekableByteChannel£ºËæ»ú·ÃÎÊͨµÀ;
· MulticastChannel£ºÔÊÐíIP¶à²¥µÄͨµÀ;
· NetworkChannel£ºÐµÄÍøÂçͨµÀ³¬¼¶½Ó¿Ú;
· ......
javaÖнӿÚÔÚ¿ª·¢ÖÐÕ¼ÖØÒªµØλ
£¨1£©½Ó¿ÚÖеÄËùÓз½·¨¶¼ÊÇpublic abstract
£¨2£©ÔÚ½Ó¿ÚÖÐÉùÃ÷·½·¨Ê±£¬²»ÄÜʹÓÃnative£¬static£¬final£¬synchronized£¬private£¬protectµÈÐÞÊηû£¬¼´Ö»ÄÜʹÓÃpublic abstract£¨Ä¬ÈÏ£©
......
javaѧϰÒÑÓжÎʱ¼ä,¸öÈ˾õµÃ,¿ìËٳɳ¤ÆðÀ´Óм¸ÖÐ;¾¶:
Ò»Åàѵ,µ½È¨ÍþµÄ»ú¹¹È¥Åàѵ,ÄÜÔÚ¶ÌÆÚÄÚ´ïµ½±È½ÏºÃµÄЧ¹û.
¶þ×Ôѧ,ÔÚ×ÔѧÖгýÁË¿´Ò»Ð©ÊÓƵ½Ì³ÌÍâ,»¹Òª¶îÍ⿴һЩ²Î¿¼Êé.ÓÐÁËÕâЩÀíÂÛ,¸ü¶àµÄÊÇҪʵ¼ù,±à³Ì¾ÍÊÇÒª²»¶ÏµÄ¶¯ÊÖ,´Ó´íÎóÖÐѧϰ,´Ó±à³ÌÖÐѧϰ,ÈÃ×Ô¼ºµÄÀíÂÛ֪ʶ¸ü¼ÓÔúʵ,ÓÐÁËÒ»¶¨µÄÀíÂÛ»ù´¡,¸öÈËÈÏΪ¿ÉÒÔ×öÓÐ ......