Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface question from Khalid and Rasmussen

 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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
 
Lisa Yanchunis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
 
Ishaan Mohan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • 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.
 
Prakshi Chopra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you all!
All the information was really helpful.
-Seema
 
corneilguy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is wrong with E) ?
 
Lisa Yanchunis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic