The Artima Developer Community
Sponsored Link

Java Answers Forum
interface Inheriting multiple interfaces

8 replies on 1 page. Most recent reply: Oct 19, 2004 2:56 AM by Nick Dwyer

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Ganesh Kumar.V

Posts: 6
Nickname: ganeshv
Registered: Oct, 2004

interface Inheriting multiple interfaces Posted: Oct 10, 2004 10:30 PM
Reply to this message Reply
Advertisement
Can any one tell me, that can an interface inherit multiple interfaces like,

public interface MyInterface extends Your1Interface,Your2Interface{
......
......
}


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: interface Inheriting multiple interfaces Posted: Oct 13, 2004 6:58 PM
Reply to this message Reply
Yes.

Ganesh Kumar.V

Posts: 6
Nickname: ganeshv
Registered: Oct, 2004

Re: interface Inheriting multiple interfaces Posted: Oct 13, 2004 9:07 PM
Reply to this message Reply
Thank you kumaran,

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: interface Inheriting multiple interfaces Posted: Oct 16, 2004 5:36 AM
Reply to this message Reply
Are we talking about Interfaces or Classes?

Multiple Interfaces: YES
Multiple Classes: NO

Class MyClassA extends MyClassB implements MyInterfaceA, MyInterfaceB, MyInterfaceC
is VALID

Class MyClassA extends MyClassB, MyClassC
is INVALID

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: interface Inheriting multiple interfaces Posted: Oct 16, 2004 11:45 AM
Reply to this message Reply
Bill Venners has a nice write up posted at:
http://www.artima.com/javaseminars/modules/PolymorphInt/index.html

I recommend referring to the online Java Language Specification at:
http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: interface Inheriting multiple interfaces Posted: Oct 16, 2004 4:37 PM
Reply to this message Reply
I can never understand why people go to all the work to post such questions and wait for answers on in a forum, when the question can be answered much more simply, quickly and authoritatively by the compiler.
interface A { void a(); }
interface B { void b(); }
interface C { void c(); }
 
public class MultipleInterfaces implements A,B,C
{
   public void a() { System.out.println("Ay!"); }
   public void b() { System.out.println("Bzzzz"); }
   public void c() { System.out.println("See?"); }
   
   public static A gimmeAnA()
   {
      return new MultipleInterfaces();
   }
   
   public static B gimmeAB()
   {
      return new MultipleInterfaces();
   }
   
   public static C gimmeAC()
   {
      return new MultipleInterfaces();
   }
   
   public static void main(String [] args)
   {
      A a = gimmeAnA();
      B b = gimmeAB();
      C c = gimmeAC();
      a.a();
      b.b();
      c.c();
   }
}


Of course, just about any introduction to Java, whether it be on the net or in a book will state the fact, as well.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: interface Inheriting multiple interfaces Posted: Oct 16, 2004 9:11 PM
Reply to this message Reply
This probably hits all the bases better:
interface A { void a(); }
interface B { void b(); }
interface C extends A,B { void c(); }
 
public class MultipleInterfaces implements A,B,C
{
   public void a() { System.out.println("Ay!"); }
   public void b() { System.out.println("Bzzzz"); }
   public void c() { System.out.println("See?"); }
   
   public static A gimmeAnA()
   {
      return new MultipleInterfaces();
   }
   
   public static B gimmeAB()
   {
      return new MultipleInterfaces();
   }
   
   public static C gimmeAC()
   {
      return new MultipleInterfaces();
   }
   
   public static void main(String [] args)
   {
      A a = gimmeAnA();
      B b = gimmeAB();
      C c = gimmeAC();
 
      System.out.println("From interface A:");
      a.a();
 
      System.out.println("From interface B:");
      b.b();
 
      System.out.println("From interface C:");
      c.a();
      c.b();
      c.c();
 
      System.out.println("From interface A again:");
      a = c;
      a.a();
 
      System.out.println("From interface B again:");
      b = c;
      b.b();
   }
}

Ganesh Kumar.V

Posts: 6
Nickname: ganeshv
Registered: Oct, 2004

Re: interface Inheriting multiple interfaces Posted: Oct 18, 2004 9:37 PM
Reply to this message Reply
Hai friend,

I thought this is a chat forum where people can clarify their doubts and not get rubbish junk replies like the one you gave me.

Any way i am pleased from your answer that java programes are compiled by java compilers.

thank you so much,

with out regards

Nick Dwyer

Posts: 4
Nickname: ndwyer
Registered: Oct, 2004

Re: interface Inheriting multiple interfaces Posted: Oct 19, 2004 2:56 AM
Reply to this message Reply
Hey Ganesh - Matt was trying to help you - but he does have a point. The question that you asked could have been solved easily by searching java.sun.com

Forums like these are really for helping you when you get stuck - not when you haven't bothered trying it out for yourself.

Go and buy a 'beginning java book' - alternatively go through the sun java tutorial see: http://java.sun.com/docs/books/javatutorial/third-edition.html or http://java.sun.com/docs/books/tutorial/information/download.html

Don't wind people up who are genuinely trying to help, especially when you are being lazy ;o)

-nick

Flat View: This topic has 8 replies on 1 page
Topic: Need to evaluate a String to make graphing calc Previous Topic   Next Topic Topic: javax.comm ring detected

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use