Results 1 to 5 of 5

Thread: how to use multiple inheritance in core java

  1. #1
    Join Date
    Dec 2010
    Posts
    87

    how to use multiple inheritance in core java

    I’m a beginner in programming and I want to know about core java. How can we use multiple inheritance in core java. I know c++ but about java I’m not sure that we can use or not. Please tell me, is it possible to use multiple inheritance in core java. If yes, than how ?. please tell me about this and give me the code from which I can understand the program. Please explain me the concept of multiple inheritance.

  2. #2
    Join Date
    Apr 2009
    Posts
    569

    Re: how to use multiple inheritance in core java

    Yes, you can use multiple inheritance in core java but not directly. You can not use multiple inheritance in a way which we are using in c++. The concept of multiple inheritance is different in core java. You can use multiple inheritance through interface in core java. In c++ we extending classes for multiple inheritance and in core java we implements a interface because class does not support in core java for multiple inheritance.

  3. #3
    Join Date
    May 2009
    Posts
    529

    Re: how to use multiple inheritance in core java

    Class does not support multiple inheritance in java. We can say it’s a disadvantage or reusability. Using multiple inheritance through classes have some disadvantagethat is why a new concept of interface is introduce. For example consider class A as superclass class B and C are sub class of A.comment : class cannot extend more than one class think class D extends B and the method present in a class A B C are different if u call a method in class than we don’t know which method we are calling either A or B or c.
    Let’s take a example:
    Take two classes say class A and class B

    class A
    {
    doSomething()
    {
    //the fun code goes here...
    }
    }

    class B
    {
    doSomething()
    {
    //serious code goes here
    }
    }

    class C extends A extends B // let's assume for a minute Java permitted Multiple Inheritence
    {

    doSomething(); //which method will it call? the method present in A or B?

    }

  4. #4
    Join Date
    May 2009
    Posts
    543

    Re: how to use multiple inheritance in core java

    Actually java has solved the problem which we are facing in c++. In c++ there is a big problem of ambiguity in multiple inheritance but in java we use interface to define a function so that no ambiguity should occur. Java is a vast but implements simplicity to avoiding ambiguity of methods and variables in multiple inheritance it also save memory. If you want a code of multiple inheritance using interface than you can search on internet for source code.

  5. #5
    Join Date
    May 2008
    Posts
    1,020

    Re: how to use multiple inheritance in core java

    Java does not support multiple interface java was designed without multiple inheritance, but it support indirectly through interface. One of the reason why java is not supporting multiple inheritance directly is ‘ambiguity’. If java allows multiple inheritance like in c++ than Jvm (java virtual machine ) doesn’t understand which method is to be call. Jvm will get confuse. So to avoid confusion and ambiguity java introduce a new concept called ‘interface’.

Similar Threads

  1. What does Inheritance mean in java?
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 11:45 AM
  2. How to achieve multiple inheritance in C sharp?
    By Rum in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 08:51 AM
  3. Various forms of inheritance in java
    By Jabeen in forum Software Development
    Replies: 3
    Last Post: 20-11-2009, 09:03 AM
  4. Replies: 3
    Last Post: 19-11-2009, 09:24 AM
  5. Multiple Inheritance in Java
    By KALINDA in forum Software Development
    Replies: 3
    Last Post: 03-11-2009, 07:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,027,969.90224 seconds with 17 queries