JAVA错误:The public type *** must be defined in its own file***


The problem of The public type c must be defined in its own file occurs because the defined JAVA class is inconsistent with the file name;
  solutions:
  1. Modify the file name to be the same as the public class;
  2. Modify the class name to be the same File name;
  3. When the subclass inherits the parent class, it does not need to be modified with public

From: https://blog.csdn.net/shengmingqijiquan/article/details/51176545


 

Note:

For example, xxx.java. There are other classes in it:

1 There are multiple classes in a file, and only the class name consistent with the file name can be declared as: public;

2. The inner class cannot be declared as: public;

3. There can only be one public class in a file

Just remove the public of the interface and the public before Frog.

package 第三周作业;

interface canSwim{
	public void swim();
}

interface canJump{
	public void jump();
}

class Frog implements canSwim,canJump{
	
	Frog() { }
	
	public void swim() {
		System.out.println("frog can swim!");
	}
	
	public void jump() {
		System.out.println("frog can jump!");
	}
}
public class Homework {
	
	public static void main(String args[]) {
		Frog A=new Frog();
		A.swim();
		A.jump();
	}
}


 

Guess you like

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/115182433