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