Talk:Interface (Java)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Interfaces and Abstract Classes[edit]

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?[edit]

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()[edit]

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 override. 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#[edit]

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 Protocol (object-oriented programming) article is both more general and more succinct than this one, and it would suffer from having all the details in this article merged into it. On the other hand, the details in this article are probably of interest to Java developers and it would be unfortunate to lose them in a merge. In addition, it would probably be confusing to have what is called an Interface in Java described using the more exact term Protocol, and even more confusing to have Protocols described as Interfaces when that term means something quite different in most object-oriented languages. This being said, I don't see why this article doesn't link to the Protocol (object-oriented programming) one (and vice versa).173.226.146.65 (talk) 00:32, 24 February 2011 (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[edit]

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[edit]

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]

Comment about Introduction[edit]

As someone who is trying to figure out what an 'interface,' (the Java kind,) is, the first sentence of this article was extremely frustrating, because it uses the word 'interface' a million times. I know that it explicitly differentiates 'generic' interfaces from the actually programming construct, but it would be nice if the article used different english words to refer to the different concepts, instead of awkwardly using the same word over and over. And another thing, when it links me to what an 'interface,' is (the Computer Science kind,) I don't think that article describes the desired kind of interface: We're not talking about GUIs (user interfaces) nor interfaces to hardware.

—Preceding unsigned comment added by 128.233.135.237 (talk) 21:26, 23 July 2010 (UTC)[reply]

Generics "extends" interface[edit]

Would it be appropriate to include information about how a generic class uses the "extends" keyword when inheriting from a base class AND multiple interfaces? For a refernce of what I am speaking of, view: http://stackoverflow.com/questions/4258447/what-does-the-java-compiler-do-with-multiple-generic-bounds . 64.55.132.4 (talk) 18:49, 2 July 2012 (UTC)[reply]

Extending interfaces[edit]

Am I right that a concrete class cannot add any new public methods if it is only implementing interfaces and does not have an "extends" relationship with a superclass? It seems to compile but will not expose the method to calling classes. -- Beland (talk) 19:01, 24 July 2013 (UTC)[reply]

Concrete Methods for Interfaces(Defender methods)[edit]

Java 8 is redefining interfaces by allowing them to implement concrete methods: http://www.javabeat.net/virtual-extension-methods-in-java-8/

I think it should be added to this page in a special java 8 section, here's the official oracle link: http://www.oracle.com/technetwork/articles/java/lambda-1984522.html — Preceding unsigned comment added by 117.194.255.24 (talk) 18:33, 30 January 2014 (UTC)[reply]

Rework into a non Java-specific 'Interface type' article?[edit]

I've had an idea regarding the proposed merge into the Protocol (object-oriented programming) article, and I've already mentioned it on the relevant threads regarding that proposal, but I figured I should mention it on the talk page for this article as well, seeing as that plan involves this article as well.

In short, reworking this article to be about Interface types in general, rather than specifically about Java's interfaces. Along the same lines as Enumerated type, Function type, Abstract type, etc. After all, Java's interfaces by themselves probably aren't notable enough for an article of their own (as per WP:NOPAGE), but, reworking this article to be primarily about interface types/language equivalents (with small sections specifically on Java/C#/TypeScript/Golang's interfaces, Python's Protocol, Rust's traits, etc) would probably be more appropriate.

I'm going to refrain from making any major changes pending the outcome of the merge/move discussions over on Talk:Protocol (object-oriented programming), but I figured I should at least mention it here in advance, whilst I'm thinking about it. 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 13:27, 14 November 2022 (UTC)[reply]