Given the code fragment:



public static void main(String[] args) {
    int iVar = 100;
    float fVar = 100.100f;
    double dVar = 123;
    iVar = fVar;
    fVar = iVar;
    dVar = fVar;
    fVar = dVar;
    dVar = iVar;
    iVar = dVar;
}

Which three lines fail to compile?

A. Line 7
B. Line 8
C. Line 9
D. Line 10
E. Line 11
F. Line 12

題解

int是32位元的整數型態;float是32位元的浮點數型態;double是64位元的浮點數型態。

int可以隱含式(implicit)轉換成float或是double,float可以隱含式(implicit)轉換成double。

所以這題float轉int的Line 7、double轉float的Line 10和double轉int的Line 12會編譯錯誤。