Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following is/are legal method declarations?

1.protected abstract void m1();

2.static final void m1(){}

3.synchronized public final void m1() {}

4.private native void m1();

  • A.1 and 3
  • B.2 and 4
  • C.1 only
  • D.All of them are legal declarations.

Answer: D

Correct answer: All of them are legal declarations.

Each combination is permitted. protected abstract is legal in an abstract class, since only private, static and final conflict with abstract. static final is legal and merely redundant, a static method not being overridable in the first place. Modifier order is free, so synchronized public final is fine. And private native is legal - a native method has no body and its implementation is supplied elsewhere.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.