Java 找不到符号。。。为什么?

Java 找不到符号。。。为什么?,java,Java,您的B构造函数需要在a中调用构造函数。默认情况下,它将尝试调用无参数构造函数,但您没有无参数构造函数,因此会出现错误。正确的解决方法是使用super调用参数化的: 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

您的
B
构造函数需要在
a
中调用构造函数。默认情况下,它将尝试调用无参数构造函数,但您没有无参数构造函数,因此会出现错误。正确的解决方法是使用
super
调用参数化的:

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
中调用构造函数。默认情况下,它将尝试调用无参数构造函数,但您没有无参数构造函数,因此会出现错误。正确的解决方法是使用
super
调用参数化的:

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(); }
}

你把A类导入到B类文件了吗?我最终发现了问题所在,但你的问题本可以更清楚。请阅读您是否将这些类添加到同一文件中?请注意,在Java中,所有类都需要位于带有.Java的文件中,还要确保您有正确的大写字母。你还必须编译A.java和B.javaNo,它们不是。公共类需要在.java中。包私有类可以有任何文件名。java。您是否将类A导入到B文件中?我最终发现了问题所在,但您的问题可能会更清楚。请阅读您是否将这些类添加到同一文件中?请注意,在Java中,所有类都需要位于带有.Java的文件中,还要确保您有正确的大写字母。你还必须编译A.java和B.javaNo,它们不是。公共类需要在.java中。包私有类可以有任何filename.java。