Jump to content

Talk:Interface (Java)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ysangkok (talk | contribs) at 01:54, 10 November 2009 ({{WikiProject Java}}). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconJava Unassessed
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
???This article has not yet received a rating on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.

Interfaces and Abstract Classes

Is it possible for an Interface to implement other interface or extend an abstract class?

No. An interface can extend other interfaces (similar to a class implementing interfaces), but it can't implement other interfaces. Semantically this is because interfaces don't contain an implementation, although syntactically, an interface extending other interfaces is the same as a class implementing interfaces, in that each allows the class/interface to inherit from and assume the types of one or more interfaces. An interface can not extend an abstract class because although the class is declared as abstract, the class can contain an implemention (or partial implementation), and by definition, an interface is not allowed to contain any implementation.
Hope that helps. —Doug Bell talkcontrib 06:38, 10 November 2006 (UTC)[reply]

Can someone who understands the concepts please review this?

This article is barely readable. Here is a quote from it: "Interfaces are used to collect like similarities which classes of various types share, but do not necessarily constitute a class relationship."

I believe that if you take the world "like" out of the sentence, you can understand it better.

Interface connection has method createStatement()

but can any interfaces(e.g Connection) have defined methods(e.g createStatement)?

An interface will not have any body(definition) in it's method. It's methods are made to be overrode. Think of an interface as a contract. Every method in that contact must be used in your class. You must implement all methods from an interface in the class that will use it. In that class you will override the interfaces methods and give them their body .

here is a sample interface

public interface DriveCar {

  // constant declarations, if any


 //notice the methods have no bodies
  int switchLane(double mph, double mphFinal);
  int Turn(boolean turnSignal);
  

}

C#

There are identical interfaces in C#. exe 15:31, 27 August 2007 (UTC)[reply]

Not just C#, but just about in any OOP language; there is no reason this article should document just one language. However, the merge with Protocol (object-oriented programming) was opposed, go figure. -- intgr #%@! 07:31, 28 August 2007 (UTC)[reply]
The C# interfaces were copied from Java. They can be documented in the appropriate article. Mike0001 (talk) 12:45, 21 February 2008 (UTC)[reply]

Rewording

Hi, I have re-worded parts of this, hope everyone approves of the new version. It needs an example of interfaces with embedded classes and interfaces. Can anyone think of examples to fit the existing ones? Mike0001 (talk) 12:20, 22 February 2008 (UTC)[reply]

Examples

The example in the Examples section doesn't demonstrate the usefulness of an interface... now it's a pretty awkward construction to let a monster roar, but that shows nothing.. it doesn't show that an interface can be used to implement a level of abstraction in an application. - Simeon (talk) 11:17, 1 July 2008 (UTC)[reply]

I've removed it for now. - Simeon (talk) 11:20, 1 July 2008 (UTC)[reply]