Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Misc Interface Questions.

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just can not find the answer to these question.
1. When an interface extends another interface. Can it extend more than one interface?
2. When an interface extend another interface. Do you have to implemnt all if the extended interface methods.
3. When an interface implement's another interface. Can it implement more than one interface?
4. When an interface implement's another interface. Do you have to implemnt all if the implemented interface methods.
TIA, Monty6
 
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 monty6:
I just can not find the answer to these question.
1. When an interface extends another interface. Can it extend more than one interface?


Yes. When you actually implement the interface, you're required to define all the methods in all interfaces that the implemented interface extends, or you get an error when compiling.



2. When an interface extend another interface. Do you have to implemnt all if the extended interface methods.


interface interface1{
public void method1();
}
interface interface2{
public void method2();
}
interface interface3 extends interface1, interface2{
public void method3();
}
public class tester implements interface3{
public void method1(){}
public void method2(){}
public void method3(){}
// ... and so on.
}



3. When an interface implement's another interface. Can it implement more than one interface?


An interface cannot implement another interface. It can only extend.



4. When an interface implement's another interface. Do you have to implemnt all if the implemented interface methods.


See above.
 
Yuhri Hirata
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I should have added: when you extend an interface in an interface, you have to make sure that if the super-interfaces each have methods with the same names and parameters, they also have to have the same return type or the compiler will throw an error.
This makes perfect sense if you think about it.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank-you, interfaces now make sence.
Summary:
An interface can only implement 0 to many interfaces.
An interface can not extend any other interface.
An class can only imlement 0 to many interfaces.
The rules of overridden methods also apply to interface methods and there super interface methods.
Monty6
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi monty
u r wrong when u say
An interface can only implement 0 to many interfaces.
An interface can not extend any other interface.
An interface can only extend 0 to many interfaces.
An interface can not implement any other interface.
regds,
Rahul
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops my mistake when i copied, pasted, & edited
tHANKS, mONTY
 
reply
    Bookmark Topic Watch Topic
  • New Topic