问:抽象的(abstract)方法是否可同时是静态的(static),是否可同时是本地方法(native),是否可同时被synchronized修饰?
答:
实例说明:
public abstract class Demo {
int a;
public Demo(int a) {
this.a = a;
}
public abstract static void f1(); //报错
public abstract native void f2(); //报错
public abstract synchronized void f3(); //报错
private abstract void f4(); //报错
abstract void f5(); //编译通过
}
编译报错:
The abstract method f1 in type Demo can only set a visibility modifier, one of public or protected
The abstract method f2 in type Demo can only set a visibility modifier, one of public or protected
The abstract method f3 in type Demo can only set a visibility modifier, one of public or protected
The abstract method f4 in type Demo can only set a visibility modifier, one of public or protected
abstract 方法只能用访问修饰符 public 或者protected!
原文地址:https://blog.csdn.net/hz_lizx/article/details/54970797