• 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

Interface question from Khalid and Rasmussen

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
In this book there is question 6.12 which is as follows:
Q. Which of these statements about interfaces are true?
Select all valid answers.
a) Interfaces permit multiple implementation inheritance.
b) Interfaces can be extended by any number of other interfaces.
c) Interfaces can extend any number of other interfaces.
d) Members of an interface are never static.
e) Members of an interface can always be defined static.

and the correct answer is : b and c
I don't understand how c is correct. Interfaces can IMPLEMENT many other interfaces, how can they EXTEND any number of interfaces?
does any one know why c is a valid statement?
Thanks
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it is a quite common practice in the "real world"
Read the following thread for a common pattern in implementing beans
http://theserverside.com/patterns/thread.jsp?thread_id=1322
Lisa
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interfaces can be extended by any number of other interfaces.
Interfaces can extend any number of other interfaces.
Interfaces can IMPLEMENT many other interfaces- Wrong.
A class can implement many other interfaces but a interface can extend(not implement) other interfaces.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Seema Das:
Hi all,
In this book there is question 6.12 which is as follows:
Q. Which of these statements about interfaces are true?
Select all valid answers.
a) Interfaces permit multiple implementation inheritance.
b) Interfaces can be extended by any number of other interfaces.
c) Interfaces can extend any number of other interfaces.
d) Members of an interface are never static.
e) Members of an interface can always be defined static.

and the correct answer is : b and c
I don't understand how c is correct. Interfaces can IMPLEMENT many other interfaces, how can they EXTEND any number of interfaces?
does any one know why c is a valid statement?
Thanks


 
Prakshi Chopra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Seema Das:
Hi all,
In this book there is question 6.12 which is as follows:
Q. Which of these statements about interfaces are true?
Select all valid answers.
a) Interfaces permit multiple implementation inheritance.
b) Interfaces can be extended by any number of other interfaces.
c) Interfaces can extend any number of other interfaces.
d) Members of an interface are never static.
e) Members of an interface can always be defined static.

and the correct answer is : b and c
I don't understand how c is correct. Interfaces can IMPLEMENT many other interfaces, how can they EXTEND any number of interfaces?
does any one know why c is a valid statement?
Thanks


Yes as regard to Interfaces we can use multiple inheritance ( not multiple implementation inheritance )
Statement: interface mylistener extends windowListener, actionListener
is perfectly valid, because java allows multiple inheritance in case of interfaces and not in case of classes. For further detail see page 197 Extending Interfaces (khalid A Mughal)
 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all!
All the information was really helpful.
-Seema
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is wrong with E) ?
 
Lisa Yanchunis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One other note:
Another common reason for extending rather than implementing an interface is that there may be only ONE method that you want to implement from an interface with a large number of methods. If you extend it you only have to implement the one method you want to use (as an overriding method) and don't have to implement the remainder as you would have to if you implemented it.
 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by corneilguy:
what is wrong with E) ?


mambers of interface are implicitly static. The variables are
implicitly public static final and methods are implicitly static. Thats why should not be declared as static.
Thanks
 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lisa Yanchunis:
One other note:
Another common reason for extending rather than implementing an interface is that there may be only ONE method that you want to implement from an interface with a large number of methods. If you extend it you only have to implement the one method you want to use (as an overriding method) and don't have to implement the remainder as you would have to if you implemented it.



Lisa,
but if you extend an interface and override just one method and do not give implementation for other methods, then I believe the class would need to be declared as abstract. am I right?

Thanks
Seema
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic