Board logo

標題: [疑難] 問一個有關SCJD考題的問題 [打印本頁]

作者: 霧隱雷藏    時間: 2009-10-28 16:45     標題: 問一個有關SCJD考題的問題

Given:
1. package test1;
2. public class Test1{
3. static int x = 32;
4. }
1. package test2;
2. public class Test2 extends test1.Test1{
3. public static void main(String[] args){
4. System.out.println("x=" + x);
5. {
6. }
What is the result?
Answer:
Compilation fails because of an error in line2 of class Test2

是不是因為「test1.Test1」的關系嗎?
如果知道原因的人可以詳細跟我說一下,為什麼錯誤嗎?
謝謝
作者: jayzhou_2046    時間: 2009-11-2 12:04

以下是javac的編譯結果:
Test2.java:4: x is not public in test1.Test1; cannot be accessed from outside
ckage
System.out.println("x=" + x);
                          ^
1 error




歡迎光臨 香港 Xocat Forum 討論區 (http://p.xocat.com/p/) Powered by Discuz! 6.0.0