Multiple markers at this line - Syntax error on token(s), misplaced construc

renyue193 2016-12-26 08:58:04
求大神,谢谢
package a;


public interface aaa{
public int getMax();
String getMes();
}
import a.aaa;

public class test implements aaa{
public int getMax(){
int i=123;
return i;
}
public String getMes(){
String s="eee";
return s;
}
public static void main(String args){
test t=new test();
int i=t.getMax();
String s=t.getMes();
System.out.println(i);
System.out.println(s);
}

}
报错信息
Multiple markers at this line
- Syntax error on token(s), misplaced
construct(s)
- The public type aaa must be defined in its
own file
...全文
924 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱睡觉的阿狸 2016-12-26
  • 打赏
  • 举报
回复
另外,同包和同类的类之间互相引用,不需要import,这就是为什么我去掉import也可以的原因。
爱睡觉的阿狸 2016-12-26
  • 打赏
  • 举报
回复
引用 7 楼 renyue193 的回复:
[quote=引用 1 楼 m2200 的回复:]
interface aaa {
	
	public int getMax();

	String getMes();
}

public class test implements aaa {
	public int getMax() {
		int i = 123;
		return i;
	}

	public String getMes() {
		String s = "eee";
		return s;
	}

	public static void main(String[] args) {
		test t=new test();
		int i=t.getMax();
		String s=t.getMes();
		System.out.println(i);
		System.out.println(s);
	}

}
我能不能再问一个问题? 为什么多了import a.aaa;就报错了呢?谢谢[/quote] import a.aaa要放在interface和class定义的上面
爱睡觉的阿狸 2016-12-26
  • 打赏
  • 举报
回复
import a.aaa要放在interface和class定义的上面
renyue193 2016-12-26
  • 打赏
  • 举报
回复
引用 1 楼 m2200 的回复:
interface aaa {
	
	public int getMax();

	String getMes();
}

public class test implements aaa {
	public int getMax() {
		int i = 123;
		return i;
	}

	public String getMes() {
		String s = "eee";
		return s;
	}

	public static void main(String[] args) {
		test t=new test();
		int i=t.getMax();
		String s=t.getMes();
		System.out.println(i);
		System.out.println(s);
	}

}
我能不能再问一个问题? 为什么多了import a.aaa;就报错了呢?谢谢
renyue193 2016-12-26
  • 打赏
  • 举报
回复
引用 楼主 renyue193 的回复:
求大神,谢谢 package a; public interface aaa{ public int getMax(); String getMes(); } import a.aaa; public class test implements aaa{ public int getMax(){ int i=123; return i; } public String getMes(){ String s="eee"; return s; } public static void main(String args){ test t=new test(); int i=t.getMax(); String s=t.getMes(); System.out.println(i); System.out.println(s); } } 报错信息 Multiple markers at this line - Syntax error on token(s), misplaced construct(s) - The public type aaa must be defined in its own file
我能不能再问一个问题? 为什么多了import a.aaa;就报错了呢?谢谢
爱睡觉的阿狸 2016-12-26
  • 打赏
  • 举报
回复
不客气,可以结贴了。
renyue193 2016-12-26
  • 打赏
  • 举报
回复
引用 1 楼 m2200 的回复:
interface aaa {
	
	public int getMax();

	String getMes();
}

public class test implements aaa {
	public int getMax() {
		int i = 123;
		return i;
	}

	public String getMes() {
		String s = "eee";
		return s;
	}

	public static void main(String[] args) {
		test t=new test();
		int i=t.getMax();
		String s=t.getMes();
		System.out.println(i);
		System.out.println(s);
	}

}
我发现问题了,是因为多了import a.aaa; 可是好奇怪啊,明明是照着书抄的,都能有问题。 谢谢你指出我的问题,以后会更加注意一些的
renyue193 2016-12-26
  • 打赏
  • 举报
回复
哎?确实能过哎,可是和我的差在哪里?为什么我的就是不对呢
爱睡觉的阿狸 2016-12-26
  • 打赏
  • 举报
回复
指出你的三点错误: 1.一个java文件里不要有两个public修饰的类或接口,内部类除外。 2.类名要以大写字母开头,这比较规范,我上面代码虽然也是小写字母开头,那是为了迎合你的风格。 3.main方法里的形参是String[],String数组,而不是String
爱睡觉的阿狸 2016-12-26
  • 打赏
  • 举报
回复
interface aaa {
	
	public int getMax();

	String getMes();
}

public class test implements aaa {
	public int getMax() {
		int i = 123;
		return i;
	}

	public String getMes() {
		String s = "eee";
		return s;
	}

	public static void main(String[] args) {
		test t=new test();
		int i=t.getMax();
		String s=t.getMes();
		System.out.println(i);
		System.out.println(s);
	}

}

50,544

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧