How does Java achieve multiple inheritance using interfaces

Java does not allow multiple inheritance through classes as classes might contain methods with same names. what happens if a class implements two interfaces with same method names?
I am really confused abt this? Can anybody help me out?
Message was edited by:
vijkris

yes to avoid the ambiguous functions which can result due to multiple inheritance of classes like in c++ , java doesn't have this through classes. But if you have same method (both return type and parameter) then java doesn't bother and it won't complain as ultimately only one implementation is possible in deriving class even though method declalaration is there in both the interfaces. If return type changes then it won't compile as it can't overide the both methods as they have same name and different return types. thats why inside interfaces they restricted the implementation of methods so that it can work fine in ambiguous scenarios.

Similar Messages

  • Why java does not support multiple inheritance ???

    Hai friends ..iam new to java .. i have doubt ..plz help me
    Why java does not support multiple inheritance ???

    The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal.
    To understand multiple inheritance, the learner needs some level of expertise like virtual derivations etc in c++. Multiple inheritance will allow method duplication, and throws the learner into confusion which method might be called by the compiler in which scenario at run time.
    Even though this answer seems to be funny, this is the actual reason why java omitted multiple inheritance of classes.
    But java support multiple inheritance of interfaces. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.

  • How java support multiple inheritance by the use of interface.

    As per my understanding, Interface is just having the signatures of the methods not the implementation.
    So How java support multiple inheritance by the use of interface?
    Answer 1: we can institate interface reference by its implemented
    class.
              ����� interface inf...
              ����� class aa implements inf..
              ����� class bb implements inf....
               Now, inf i = new aa();
               inf i = new bb();
    Answer 2: We can extends as many interface as we want in the
    single
               interface.
               i.e. interface infFirst....
               interface infSecond....
               interface infThird....
               Now ,
               interface ingMulti extends infFrist, infThird...
    By above two answers its not prity clear as per the multiple inheritance in C or C++.
               i.e.
               class first{
               method abc();....}
               class second{
               method bbc()......}
               class multi::first::second{
               we can call to abc();.....as well as bbc();
    -Please give your important suggstion on the same.(Hope I explain it well.)
    -Jeff

    The keyword implement is used only for interfaces not
    for abstract class. If i am wrong correct me.I believe your right, but I will double check.
    As for the multiple inheritence think about the following code:
    class Animal {
        //  Animal generic stuff in this class
    interface Eat {
        //  Generic stuff that models eating behavior
    interface Runs {
        //  generic methods that model running behavior
    public class Horse extends Animal implements Eat, Runs {
        //  Stuff specific to a horse
    }The Animal class is generic but has stuff in it common to all animals.
    The Eat interface models behavior that is generic to eating, all living things have to eat something to survive. Herbavore are different from carnivores.
    The Runs interface models generic behavior to running, such as speed. A cheeta definately runs faster than a human.
    This brings us to the Horse class. It extends the Animal class because it "is-a" animal, and it implements the eat and runs interface because they are behaviors a horse has.
    I hope that helps.
    Extending an abstract class is the same as extending a regular class with the exception you MUST override all abstract methods in the abstract class. Thats not too difficult but I believe when designing classes, designing an abstract can be more diffecult than modeling the base class, and generic behaviors in interfaces. JMO.
    JJ

  • How too ? Multiple inheritance with Interface ?

    I understand that Java does NOT allow Multiple inheritance. I've read many posts trying to understand the interface statement.
    I understand that an interface implements a behavior! But can someone please explain how I would inherit Multiple classes (Thread and JPanel) using an interface ?
    Many Thanks,
    Rob

    I understand that an interface implements a behavior!No, it doesn't. It merely defines what methods must be present in a type. A class is what actually implements the behavior for a particular implementation of that type.
    But can someone please explain how I would inherit
    Multiple classes (Thread and JPanel) using an
    interface ?You can't. Thread and JPanel are classes. A given class can only extend one class.
    A class can implement multiple interfaces however. So if at least one of Thread or JPanel were an interface, then your class could inherit from both of them. But that's not the case, so you can't.

  • How does java.exe behave if I only use -Xmsn option?

    Hi,
    if I only set the -Xmsn option and do not set -Xmxn option when I launch my Java application, how does java.exe behave? Does the heap will automatically grow like what Bea's JRockit does when my application requires more memory?
    I use JDK 5.0.
    Thanks for your help!

    If your application needs the space, the JVM will grow the heap up to the
    default value of -Xmx. Note that it will run a garbage collection cycle before
    expanding the heap, and it may take a few or several cycles to expand to
    the -Xmx value. How fast or slow it expands depends somewhat on the
    behavior of your application (how much it allocates and how long the
    objects live).
    The default value of -Xmx depends on the platform; see
    http://java.sun.com/docs/hotspot/gc5.0/ergo5.html.

  • HT5243 How does one know if they use "java applets"? What do they do? How will I know if I need to 'disable the java web plug-in browser' if I do not use them? ( I'm not very literate in computer-speak.

    How does one know if they use "java applets"? What do they do? How will I know if I need to 'disable the java web plug-in browser' if I do not use them? (Obviously I'm not very literate in computer-speak.)

    Well, when you go to a web page a section of the web page will have a coffee cup picture where the java applet will run. The applet loads then runs. If you are not seeing this behavior then you are not using java. If it make you feel more comfortable then disable the browser java plugin. On my machine I have not disable java- but you
    may what to.

  • How does java implements runtime polymorphism.?

    Hi all.
    we know how does runtime polymorphism take place in java.
    But my quesions is , how does java implement it internally.
    in C++, with the use of keyword virtual , complier decides to make a call at runtime using virtual table and Vptr.
    like in c++,
    class base {
    public:
    virtual void show(){
    cout<<"I am in base class"<<endl;
    class child : public base {
    public:
    void show(){
    cout<<" I am in child class"<<endl;
    int main(){
    base*p = new child();
    p->show();
    return 0;
    out put - I am in child class.
    but if we remove the virtual keyword then output
    I am in base class..
    We know how it happens
    but in java
    class base {
    void show(){
    System.out.println("I am in base class");
    class child extends base {
    void show(){
    System.out.println(" I am in child class");
    class demo {
    public static void main(string args[ ]){
    base b;
    child c = new child();
    b = c;
    b.show();
    output is - I am in child class
    but how can i bring the output as
    I am in base class ---
    complier knows that b is base reference so y doesnt it just use base version.

    if all methods are virtual..then we should always have runtime binding but we do have early biding too.
    shouldnt we able to call base verison using a base reference variable like in c++.
    May be I m mixing big times java n c++. But it seems to me as core java is much like c++ . The things u can do in c++ , u can do same in java in different ways.

  • Java Gurus: How does Java compare to 4GLs?

    I've been using Java for a year now. I love Java. As a 3GL, how does Java compare to a 4GL?
    (I can't say I know a whole lot about fourth generation languages. The only 4GL that I'm a little familiar with is Clarion.)
    What are your thoughts?

    What is 3GLs and 4GLs? You mean Programming Language and Scripting Language?

  • Hi All , Will Java supports Multiple Inheritance  classes???

    Hi All ,
    Will Java supports Multiple Inheritance by classes???
    Thanks in advance,
    Prakash

    No, Multiple inheritance would look like
    public class A extends B,C {(You can do that in C++, but it's rarely a good idea).That's not true at all. It's not inherently harmful, in C++ or any other language. It's entirely possible to do it correctly when it truly makes sense.
    Java just guarantees that nothing bad can happen to you by only allowing multiple inheritance of interface. You can't ever have multiple inheritance of implementation, that's all.
    %

  • How does one copy a dvd using disk utility?

    How does one copu a dvd using disk utility?

    By following the instructions in the os Help menu and Disk Utility "Help." 

  • How does java support the concept of destructor?

    How does java support the concept of destructor?

    @KunalSurana: before you flood the forum with basic questions, do us a favour and read.
    [Sun's basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
    [Sun's New To Java Center|http://java.sun.com/learning/new2java/index.html]
    Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    jGuru
    A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch
    To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    [Yawmarks List|http://forums.devshed.com/java-help-9/resources-for-learning-java-249225.html]
    [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance]
    [http://javaalmanac.com|http://javaalmanac.com]
    Bruce Eckel's [Thinking in Java(Available online.)|http://mindview.net/Books/DownloadSites]
    Joshua Bloch's [Effective Java|http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]
    Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance ]
    James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]
    Gosling is the creator of Java. It doesn't get much more authoritative than this.
    Joshua Bloch and Neal Gafter [Java Puzzlers.|http://www.javapuzzlers.com/]

  • How does one print single photos using iPhoto. I keep getting an error message:No Available Themes

    How does one print single photos using iPhoto. I keep getting an error message:No Available Themes

    You need to reinstall iPhoto. To reinstall iPhoto delete the current application and, on all Macs with Snow Leopard or earlier installed, all files with "iPhoto" in the file name with either a .PKG or .BOM extension that reside in the:
    HD/Library/Receipts folder (10.5 and earlier)
    or from the /var/db/receipts/  folder (10.6) .
    Deleting receipts is not necessary if your Mac came with Lion or later preinstalled.
    Then install iPhoto from the source it came from originally.
    OT

  • What is the output of Maya and how does Java use it in animation.

    What type of software is used and what input and output files are created in the animation process?
    From what I read:
    Maya is used to create polygon structures, perform rigging, and it attaches surface textures which are made in Photoshop. Then Maya creates key images or positions of the animation. Next Maya exports an image and a data file to do the neccessary transformations. Finally, Java uses the image and the data file to paint the images and their position based on the game logic's use of the data file.
    What have I missed or described wrong?
    I also need more clarity on the input files to Java and how Java stores and uses these files. The use of Maya images and files seems different. Is Maya or Java doing the transformations or are they both doing them? How does this work?
    Thanks for your help
    Jon

    Thanks for the explanations. What this means in my situation is that tags are an unnecessary way of spending a lot of time making my file system more complicated, without adding any value whatsoever. Without tags, I can find any of my 3,000 files with a few clicks. (On my computer, Spotlight has cobwebs. I very rarely need it, but it's wonderful when I do.) Now that I know how tags work, I can ignore it.
    A human being can only perceive a quantity of seven without counting or grouping; hence we arrange things in structures to keep the number of entitites low on each level. You don't need to count three objects to know that they are all there, but you do need to count twelve objects. Which is why Home Alone was believable. We sort screws and nails in jars and toolboxes have compartments. Even the grocery store has a hierarchical arrangement. You don't find steaks in the bakery section, or breakfast cereal in the produce department.
    Some people aren't organized, and that's not a bad thing, but no folder, no tag, and no group is going to change a fundamental personality characteristic.
    Thanks everyone for showing me that in my case, there's no point to tags. That saves me a lot of time.

  • How does FF handle multiple ip addresses on the device?

    Hi
    I was wondering if someone could point me at documentation or explain how FF handles the situation where the device has multiple IP addresses ie an Ethernet card and a wireless card active at the same time and with different networks associated with each device. How does FF decide which interface to use and is there someway of making it use a particular interface always...
    tia
    nava

    Windows Vista and 7 give priority to the wired Network. So if you have Wireless and Wired connected, Windows will (by default) use the wired. Firefox uses what Windows does, so it will also use the Wired network. The only way that I know of to force Firefox to use one network over the other is to disconnect or disable the unwanted network. But this sort of thing is primarily handled through the OS, not Firefox.
    Also, you should update to Firefox 11, as Firefox 9 has some pretty big security holes that have been patched in 11.

  • How can I return multiple values using Oracle 9i Web Services ?

    Hi, Is it possible to return multiple parameters using WebServices in general ? And if yes, how do we do it using Oracle 9i WebServices ?
    At my client usually I call
    return_value = SoapClient.MehtodName(param1, param2, param3)
    If i need more than one return_value...how do we handle that ?
    Thanks,
    -Krishna

    Anyone has any ideas about this ?
    And also if i want a collection in one of the input parameters...how to do that ?
    Does Oracle WS have any such support ? Or we have devise our own way like sending it by separators or something like that ?
    Thanks,
    Krishna

Maybe you are looking for

  • Retrieving cell values from html in servlet - help!

    Dear all, I've got a table. I want to put links in each cell box. No problem. However I want to know when i've moved to my link what number cell the link came from. This is proving to be a big problem. Here is what i've tried: writer.println("<TR><TH

  • Default Colors Limit for Graph in OBIEE 11g

    Hi, I'm using OBIEE 11g (11.1.1.6.6) When I use a graph (either bar or pie), I notice that OBIEE only has 12 default colors to use in the graph. So it starts from blue, red, and so forth, until the 12th color, then for the 13th color it will use the

  • 2009 13' MacBook Pro Crashing - Due to battery/CPU?

    Hi guys, first post here, been meaning to post this for a while and finally am because I guess i'm at my wits end with this problem. So heres the problem: Lately (past few months), my CPU seems to not respond well to Safari's flash plugin. When I che

  • Help required in SQL query

    I have a table and cols as below: START DATE     TOTAL DAYS 10/11/2011 15:00      1 10/15/2011 5:00      1 12/22/2011 10:00     1 12/22/2011 11:00     2 12/30/2011 10:00     1 1/1/2012 1:00     1 1/1/2012 10:00     1 1/1/2012 16:00     2 1/2/2012 14:

  • Dialog box for canvas

    Hi guys, I want canvas size for square before Canvas that i want dialog box which side i want canvas Top Left Right Bottom Centre After Click any one i want Canvas that images in that side