import java.util.*;
public abstract class Player {
abstract String nm;
public abstract void displayDetails();
}
class Booking extends Player {
nm = "Sam";
void displayDetails() {
System.out.println("Name is:" + nm);
}
}
//代码产生错误:标识符期望nm =" sam&#34 ;;
答案 0 :(得分:0)
在Java中,您应该仅将表达式保留在块内。你不能在那里保留nm = "Sam";
,在实例初始化块中移动它
import java.util.*;
public abstract class Player {
String nm; // instance fields cant be declared as abstract
public abstract void displayDetails();
}
class Booking extends Player {
{ // instance initialization block
nm = "Sam";
}
void displayDetails() {
System.out.println("Name is:" + name);
}
}