1
class A
{
int i,j;
A (int x, int y)
{
i = x;
j = y;
}
void show()
{
System.out.println("the value of i and j are " + i + " " + j);
}
}
class B extends A // here is the error
{
int k;
B (int z, int a, int b)
{
k = z;
i = a;
j = b;
}
void display()
{
System.out.println("the value of k is " +k);
}
public static void main (String args[]) {
A a = new A(5,10);
/*a.i = 5;
a.j = 10; */
a.show();
B b = new B(2,4,6);
/*b.i = 2 ;
b.j = 4;
b.k = 6;*/
b.show();
b.display(); }
}
您是否在B文件中導入了您的A類? – vodkhang 2010-09-20 08:15:15
我發現最終有什麼問題,但是你的問題可能會更清晰。請閱讀http://tinyurl.com/so-hints – 2010-09-20 08:16:44
您是否將這些類添加到同一個文件?請注意,在Java中,所有類都需要在.java文件中。同時確保您擁有正確的大寫字母。你也必須編譯A.java和B.java –
Thirler
2010-09-20 08:17:12