This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple inheritance Topic, need answer!!!!!!!  RSS feed

 
mahendrakumar manchi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dude,
i got a problem with the interfaces topic, suppose i have this pgm,

interface sam1{

public void m1();

}

interface sam2{

public void m1();

}
class sample implements sam1,sam2{

public void m1(){
System.out.println("Sample");
}

public static void main(String args[])
{
sample s=new sample();
s.m1();
}
}


Hence i compiled the program, no error will come,but i want to know that which m1() will be overridden first and how the java analyses this type of concept.........

Please reply guys,.......
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahendrakumar,
Welcome to JavaRanch!

First, note this isn't really multiple inheritance. Inheritance refers to the extends keyword and means you "inherit" the implementation of superclasses.

When implementing an interface, you are simply declaring that you will implement a method with a certain signature. Since both interfaces have the same signature, you satisfy both these promises with a single method.
 
mahendrakumar manchi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Jeanne,

Yes the concept of interface is to support multiple inheritance,and it is used to declare the methods that should be implemented in subclasses, but i should know one thing, in the above given program,which method m1()in both interfaces will be overridden first and how the interpreter checks this condition?...................
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither method is overridden. A method is implemented which has the same signature as both m1() methods. Whether the compiler looks at sam1 or sam2 first is rather meaningless. It is like asking which is better of these two possibilities:
 
mahendrakumar manchi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't use abbreviations like "u" for "you."

I have already told you, neither method is overridden, they are implemented. Overriding means altering a method which has already been implemented.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!