The first time I run the code fine. However, when i try to run the code again.
Error:
cannot find or load main class Dog;
cause:java.lang.NoClassDefFoundError: dog (wrong name: Dog)
Code:
public interface animal{
default void greet(animal a){
System.out.println("Hello,Animal");
}
default void sniff(animal a){
System.out.println("sniff animal");
}
default void praise(animal a){
System.out.println("u r a good animal");
}
}
public class Dog implements animal{
@Override
public void sniff(animal a){
System.out.println("dog sniff animal");
}
void praise(Dog d){
System.out.println("u r a good dog");
}
public static void main(String[] args) {
Dog d = new Dog();
animal a=new Dog();
a.greet(d);
a.sniff(d);
d.praise(d);
a.praise(d);
}
}
I tried many solutions provided by others, most are useless. One solution that works is that I changed jdk version. But it’s not so useful. When I changed the jdk version , the first run has no problem. The second time I want to run the program, the same error occurs. So I wonder know why this happen when I tried to run the program again.
Willt is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.