Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can Interface Implement and extend? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can Interface Implement and extend?" Watch "can Interface Implement and extend?" New topic
Author

can Interface Implement and extend?

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
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


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Have you thought of writing some code to test your hypothesis?


What do you get?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
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

Joined: Aug 03, 2002
Posts: 7729
And:



The constants A.a and B.b get inherited by C.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Aug 28, 2005
Posts: 340
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can Interface Implement and extend?
 
Similar Threads
Interface(URGENT)
extends interface
Interfaces
Inner classes must extend?