• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract Method

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following statements are true?

a) An abstract method cannot be final
b) An abstract method cannot be static
c) An abstract method cannot be private
d) An abstract method must be specified inside an abstract class only
e) An abstract method cannot throw any exceptions
Select all valid answers.
The answers mentioned were (a),(b),(c)&(d).Should (d) be included since,abstract methods can also be specified within an interface ?

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No since by default all the methods in an interface are abstract.
So the correct answers are (a),(b),(c) and (d).

regards.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiya,
An interface cannot have a static member, according to the JLS 2nd Ed.
9.4
Note that a method declared in an interface must not be declared static, or a compile-time error occurs, because static methods cannot be abstract.
End Quote.

All methods within an interface are implicitly abstract since there is no implementation. And they are implicilty public, so you cannot declare any private methods (however, you can implement private members in the implementation).
A method declared within an interface may not be declared as final, although the implementation of the method in a class that implements the interface can be declared as being final.
Methods defined within an interface can be declared as throwing an exception.
 
reply
    Bookmark Topic Watch Topic
  • New Topic