• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

can Interface Implement and extend?

 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have some doubts regarding Interfaces?

a) Can an Interface implement another interface?
b) How can an Interface extend more than one Interface?
c) If Interface can Implement as well as extend other Interfaces, then what is the difference between Extending and Implementing Interfaces?
d) When you extend an Interfaces, do you also extend all the Constants declared in Super Interfaces?

Hope Someone would help

Sandy
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you thought of writing some code to test your hypothesis?


What do you get?
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir,
I had tried the code....and i did not compile

test25.java:2: '{' expected
interface B implements A { }
^
test25.java:7: '}' expected
}
^
2 errors

since the error are not descriptive, so i concluded that either this is not the way to implement interfaces, or you cannot implement an interface

the post was just to confirm that if i am right.

anyways my 2nd questions is still unanswered
b) How can an Interface extend more than one Interface?(while in jave we can extend only one class )
[ September 12, 2005: Message edited by: Sandeep Chhabra ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And:



The constants A.a and B.b get inherited by C.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I suggest that you refer to the Java Language Specification or to a good Java book?

For instance: "The Java Programming Language, Fourth Edition" by Arnold, Gosling, Holmes
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think about it this way. An interface does not implement any of the methods that it specifies, it is left to a class to implement interface and provide an implementation for the methods. So an interface will not implement anything from its superinterfaces. It can only extend the superinterface perhaps by adding more method specifications for its implementing classes to implement.

By definition a class can implement zero or more interfaces but can only extend one superclass. This is a choice made by the designers of the Java Specification, they did not choose to follow the model of C++ where you can extend multible superclasses.
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot Mr. Barry Gaunt

You have been a great help to me...i have learned a lot from you till date..
and i wish to keep learning from all u people in the same way..
and thanx for your suggetions i would surely consider it.

Your help is highly Appreciated.

Thanx
[ September 12, 2005: Message edited by: Sandeep Chhabra ]
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic