[JAVA rookie] asked a question about access rights, and the writing interface encountered an error

The

code is as follows:

interface PCI {
    void start();
    void stop();
}

class GraphicsCard implements PCI {
    public GraphicsCard() {
        System.out.println("");
    }

    void start() {
        System.out.println("");
    }

    void stop() {
        System.out.println("");
    }
}


class SoundCard implements PCI {
    public SoundCard() {
        System.out.println("");
    }

    void start() {
        System.out.println("");
    }

    void stop() {
        System.out.println("");
    }
}


class NetCard implements PCI {
    public NetCard() {
        System.out.println("");
    }


    void start() {
        System.out.println("");
    }

    void stop() {
        System.out.println("");
    }


}

class TestPCI {
    public static void main(String[] args) {
        GraphicsCard a = new GraphicsCard();
        SoundCard b = new SoundCard();
        NetCard c = new NetCard();
        a.start();
        a.stop();
    }
}

execution problems are as follows :

clipboard.png

I can see that there is something wrong with the permission, but I still don"t understand why it went wrong.

Aug.03,2021

the default access permission for the Java method is package-level

The methods of

interface are all public

by default.

so it is not allowed for you to overwrite public with package-level permissions

The property in the

interface is constant, and the method is public,. This is fixed, so you can omit it, but there is no write permission in your later class, so the default default, plus public is fine


the code that implements the interface method in the GraphicsCard class, SoundCard class and NetCard class is changed to

@ Override
public void start () {

System.out.println("");

}


your interface definition method is not modified by public, and the implemented method cannot be modified by public. If you don't add public, to all the methods in interfaces, the permissions of the implemented public, implementation method must be consistent with the interface

.
Menu