• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic