JAVA¹æ·¶Ñ§Ï°——static³ÉÔ±³õʼ»¯
class Super { static int taxi = 1729; }
class Sub extends Super {
static { System.out.print("Sub "); }
}
class Test {
public static void main(String[] args) {
System.out.println(Sub.taxi);
}
}
Êä³ö£º1729
֪ʶҪµã£º
A reference to a class field causes initialization of only the class or interface
that actually declares it, even though it might be referred to through the name of a
subclass, a subinterface, or a class that implements an interface.
Ò²¾ÍÊÇ˵ֻÓÐʹÓøÃÀà»òÕß½Ó¿ÚÖ±½Ó¶¨ÒåµÄÀà±äÁ¿£¬²Å»á¼¤·¢¸ÃÀàµÄ³õʼ»¯£»Èç¹ûʹÓõÄÊÇÆä¸¸ÀඨÒåµÄÀà±äÁ¿£¬Ôò×ÓÀ಻»á±»³õʼ»¯
interface I {
int i = 1, ii = Test.out("ii", 2);
}
interface J extends I {
int j = Test.out("j", 3), jj = Test.out("jj", 4);
}
interface K extends J {
int k = Test.out("k", 5);
}
class Test {
public static void main(String[] args) {
System.out.println(J.i);
System.out.println(K.j);
}
static int out(String s, int i) {
System.out.println(s + "=" + i);
return i;
}
}
Êä³ö£º
1
j=3
jj=4
3
֪ʶҪµã£º
Initialization of an interface does not, of itself, cause initialization of any of its
superinterfaces.
The reference to J.i is to a field that is a compile-time constant; therefore, it
does not cause I to be initialized. The reference to K.j is a reference to a field
actually declared in interface J that is not a compile-time constant; this causes initialization
of the fields of interface J, but not those of its superinterface I, nor
those of interface K. Despite the fact that the name K is used to refer to field j of
interface J, interface K is not initialized.
Ïà¹ØÎĵµ£º
java½Ó¿Ú
ʲôÊǽӿÚ
¡¡¡¡JavaÖеĽӿÚÊÇһϵÁз½·¨µÄÉùÃ÷£¬ÊÇһЩ·½·¨ÌØÕ÷µÄ¼¯ºÏ£¬Ò»¸ö½Ó¿ÚÖ»Óз½·¨µÄÌØÕ÷ûÓз½·¨µÄʵÏÖ£¬Òò´ËÕâЩ·½·¨¿ÉÒÔÔÚ²»Í¬µÄµØ·½±»²»Í¬µÄÀàʵÏÖ£¬¶øÕâЩʵÏÖ¿ÉÒÔ¾ßÓв»Í¬µÄÐÐΪ(¹¦ÄÜ)¡£
¡¡¡¡½Ó¿ÚµÄÁ½ÖÖº¬Ò壺һ£¬Java½Ó¿Ú£¬JavaÓïÑÔÖдæÔڵĽṹ£¬ÓÐÌØ¶¨µÄÓï·¨ºÍ½á¹¹;¶þ£¬Ò»¸öÀàËù¾ßÓеķ½·¨µÄÌ ......
Map¡¢Set¡¢Iteratorµü´úÏê½â
Map½Ó¿Ú¶¨ÒåÁËËÄÖÖÀàÐ͵ķ½·¨£¬Ã¿¸öMap¶¼°üº¬ÕâЩ·½·¨¡£
equals(Object o)±È½ÏÖ¸¶¨¶ÔÏóÓë´ËMapµÄµÈ¼ÛÐÔ¡£
hashCode()·µ»Ø´ËMapµÄ¹þÏ£Âë¡£
Map¶¨ÒåÁ˼¸¸öÓÃÓÚ²å·ÅºÍɾ³ýÔªËØµÄ±ä»»·½·¨¡£
remove(Object key) ´ÓMapÖÐɾ³ý¼üºÍ¹ØÁªµÄÖµ¡£
put(object key,Object value) ½«Ö¸¶¨ÖµÓëÖ¸¶¨¼üÏà¹Ø ......
ѧϰÁËÁ½ÆªµÄRuntimeÀ࣬ÏÖÔÚ¶ÔËüÓÐÁ˸üÉîÒ»²ãµÄÁ˽⣬ÄÇôÎÒÃÇÀ´¿´¿´ÏÂÃæµÄ´úÂ룺
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader ;
import java.io.BufferedReader;
public class Exec_Output{
public static void main(String []args)throws IOException,Int ......
ÕâÑùÒ»À´£¬DelphiʹÓÃWebserviceºÍJAVAͨѶʱ£¬¿ÉÒÔ½«DELPHIµÄʱ¼äÖ±½Ó´«¸øJAVA¡£´Ó¶øÃâÈ¥ÁËʱ¼ä×Ö·û´®parseÖ®¼äµÄÏûºÄ£¬Ìá¸ßµÄ³ÌÐòЧÂÊ¡£
Delphiʱ¼äʵÖʾÍÊÇdoubleÀàÐÍ£¬ÕûÊý²¿·Ö±íʾÌ죬СÊý²¿·Ö±íʾµ±Ììʱ¼ä£¬Ã¿ºÁÃëΪ1/86400000¡£¿¼Âǵ½Ê±ÇøµÄת»»ºó£¬JAVAºÍDELPHIʱ¼äÖ®¼äµÄת»»ÀàÈçÏ£º
import java.util.Calendar ......
Java ¶àÏ̱߳à³ÌÖ®Áù£ºÏß³ÌÖ®¼äµÄͨÐÅ£¨¸½Ô´´úÂ룩
Ô´´úÂëÏÂÔØ
¶àÏ̱߳à³ÌÖУ¬Ïß³ÌÖ®¼äµÄͨÐÅÊÇÒ»¸ö±È½Ï¸´ÔÓµÄÎÊÌâ¡£´ó¼ÒÍùÍù¸ã²»¶®Ê²Ã´ÊǾºÕù×ÊÔ´£¿Ê²Ã´Ê±ºò¿¼ÂÇͬ²½£¿Ôõô½øÐÐͬ²½£¿Ê²Ã´ÊÇÏß³ÌͨÐÅ£¿Ôõô½øÐÐͨÐÅ£¿ºÜ
¶àÅóÓÑÃæÊÔµÄʱºò¶¼Óöµ½¹ýÕâÑùÀàËÆµÄÒ»¸ö±à³ÌÌ⣺¸ø¶ ......