• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

interface methods

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface Z {void m1();} // 1
class D implements Z {public final void m1() {}} // 2
class E implements Z {public synchronized void m1() {}} // 3
class G implements Z {public native void m1();} // 4

A Compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. None of the above


Answer : e (none of the above)

Interface methods are implicitly public and abstract.
How can we apply 'final','synchronized' and 'native' modifiers
to the implemeted methods?

Thanks in advance..

regards,
rajani.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The methods within the interface are implicity public and static. That doesn't mean that the class that implements those methods can't make those methods final, as well (or any of the other modifiers, for that matter).

Certainly, the implementing class couldn't change the access modifier to private, but make a public, static method final isn't a problem at all.
 
Rajani Sudhakar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another Question with Interfaces :

Is the concept of Nested Interfaces included in the SCJP1.4 exam?
And also classes defined within an enclosing interface?
If so.. can anyone send me appropriate links to know about
nested interfaces? I am entirely confused about nested interfaces..

what are the modifiers applicable to to an interface(nested) ?
what are the modifiers used to a class defined within an enclosing
interface?

A lot of questions revolving at the same time about "Nested Interfaces".


I would be greatful if anyone answers my questions..

thanks in advance,
regards,
rajani.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic