Single Choice Not Set

QWhich is the valid declarations within an interface definition?

ID: #1989 Java Language Fundamental 31,677 views
Question Info
#1989Q ID
Not SetDifficulty
Java Language FundamentalTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A public double methoda();
  • B public final double methoda();
  • C static void methoda(double d1);
  • D protected void methoda(double d1);
Correct Answer

Explanation

Option A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract.

Option B is wrong. The final modifier means that this method cannot be constructed in a subclass. A finalmethod cannot be abstract.

Option C is wrong. static is concerned with the class and not an instance.

Option D is wrong. protected is not permitted when declaring a method of an interface. See information below.

Member declarations in an interface disallow the use of some declaration modifiers; you cannot use transientvolatile, or synchronized in a member declaration in an interface. Also, you may not use the private and protected specifiers when declaring members of an interface.

Share This Question

Challenge a friend or share with your study group.