java中的分号/花括号语法错误
当我尝试以下代码时,我得到以下异常: 标记“;”上的语法错误,{应为 但当我将其更改为以下代码时,我得到了以下异常: 抽象方法不指定主体java中的分号/花括号语法错误,java,methods,syntax,interface,Java,Methods,Syntax,Interface,当我尝试以下代码时,我得到以下异常: 标记“;”上的语法错误,{应为 但当我将其更改为以下代码时,我得到了以下异常: 抽象方法不指定主体 我如何写这篇文章而不出现语法错误?我举了一个有效的例子,希望它能帮助你。如果你有任何问题,大多数评论都会尽力提供帮助 public class Test { private int array[][] = new int[10][10]; public static void main(String[] args) { Test
我如何写这篇文章而不出现语法错误?我举了一个有效的例子,希望它能帮助你。如果你有任何问题,大多数评论都会尽力提供帮助
public class Test {
private int array[][] = new int[10][10];
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.getValue(1, 5));
System.out.println(test.getValue2(2, 3));
}
//Get the value of parameters
public int getValue(int row, int column){
return (row+column);
}
//Get the value of an attribute
public int getValue2(int row, int column){
return array[row][column];
}
}
如果您想在接口上发表声明,它如下所示:
public interface TestInterface {
default int getValue(int row, int column){
return row + column;
}
}
如果这是目标,那么您会遇到一些架构问题,但我认为这只是名称“接口”而不是“类”。我认为这是一个接口类,这就是为什么您会得到“抽象方法不指定主体”错误。请浏览此链接,它可能会让您很好地了解您不在接口中实现方法(除非它们是静态或默认方法,并且您使用的是Java 8),而是在类中实现它们。这必须在接口中。您需要在接口方法声明中查找可以和不能执行的操作。
public class Test {
private int array[][] = new int[10][10];
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.getValue(1, 5));
System.out.println(test.getValue2(2, 3));
}
//Get the value of parameters
public int getValue(int row, int column){
return (row+column);
}
//Get the value of an attribute
public int getValue2(int row, int column){
return array[row][column];
}
}
public interface TestInterface {
default int getValue(int row, int column){
return row + column;
}
}