Why  multiple inheritence is avoided in java.

why multiple inheritence is avoided in java.
r there any advantages in this???
can u briefly explain with programming so that it will be clear.

Here is one of several discussions of this topic to be found on the web:
http://csis.pace.edu/~bergin/patterns/multipleinheritance.html

Similar Messages

  • I acheived Multiple Inheritence in JAVA !!!!!!!!

    Hi,
    Im in ob_imit2_a2 group. I can use member variables and methods of two(or more) classes in another class without importing them just like Multiple Inheritence in C++.
    TECHNICAL COMMENTS REQUIRED
    See Below
    ///////// Outer.java
    public class Outer implements myInterface, myInterface2{
    public Outer() {
    System.out.println("outer class");
    public void check()
         inter2.test();
         inter.test();
    ////////// myInterface.java
    interface myInterface{
    class interclass{
         interclass()
              System.out.println("SS");
         public void test()
              System.out.println("TEST");
    public interclass inter=new interclass();
    //////////myInterface2.java
    interface myInterface2{
    class interclass2{
         interclass2()
              System.out.println("SS 2");
         public void test()
              System.out.println("TEST 2");
    public interclass2 inter2=new interclass2();
    //////////// Main.java
    public class Main {
    public static void main(String abc[]) {
    Outer o = new Outer();
         o.check();
    }

    Any and all variables declared in an interface are always implicitly public, static, and final; meaning that they are constants and NOT member variables. You can call these methods directly from the main method (a static scope) as well; meaning that they are not associated with any instance of the class Outer; i.e. they are NOT inherited.
    The difference between inheritance (extending) and realization (implementing) is that when extending you inherit everything from your parent class, and while implementing you are taking up a role and agree to fulfill all the responsibilities (methods) of that role.

  • Is Java allow multiple inheritence?

    Hi,
    I am having class A and class B, and class A exteds Class B. All class in Java extends Object class by default,
    1. class B extends one class Object
    2. class A extends two classes class B and class Object.
    Now class A extending two classes is it correct?
    Kindly help me.

    RajivGuna wrote:
    Hi,
    I am having class A and class B, and class A exteds Class B. All class in Java extends Object class by default,
    1. class B extends one class Object
    2. class A extends two classes class B and class Object.
    Now class A extending two classes is it correct?
    Kindly help me.What you described isnt multiple-inheritence , more like multi-level inheritence .Java allows a maximum of one direct superclass for a class , and the situation you described doesnt violate that restriction.

  • Multiple inheritence occured in java?

    we know java doest support multiple inheritence
    we know the super class for all java classes is Object
    ex:
    class A
    class B extends A
    here A extending Object
    and B extending Object(by default ) and extendin A
    is multiple in heritence occured
    if u say its multilevel inheritence how will u prove that programatical?

    we know java doest support multiple inheritence
    we know the super class for all java classes is
    Object
    ex:
    class A
    class B extends A
    here A extending Object
    and B extending Object(by default ) and extendin A
    is multiple in heritence occuredno, multiple inheritance occurs when a type directly inherits from more than one other type
    if u say its multilevel inheritence how will u prove
    that programatical?huh ?

  • Interfaces to replace multiple inheritence

    Howdy,
    I have, conceptually, the following situation: I have a Ball abstract class. The Ball has several
    concrete methods. It also has an abstract method getAppearance (that would somehow return how a
    Ball is visualized). I have several "adjective" subclasses that I would like to build from it, for example:
    SpikyBall, GlowingBall, ColorBall, etc. I would like these classes to be concrete.
    Additionally, I would like to have a concrete class of any permutation of this list of adjectives, for example:
    SpikyColorBall, GlowingColorBall, SpikyGlowingColorBall. I want to accomplish this
    using as little code rewriting as possible, and, hopefully, none at all.
    Using certain other single letter languages that I won't name here, I used Multiple Inheritence. A
    SpikyColorBall would inherit from both SpikyBall and ColorBall, who both inherited from
    Ball. I was told I could accomplish this in Java using interfaces instead of multiple inheritence, which
    Java doesn't support. How is this accomplished? Could you give me (or forward me to) a good
    example? Again, the power I'm looking for is multiple inheritence's code-reusability.
    As a side note, why did Java choose to use interfaces instead of multiple inheritence?

    Courtesy of yawmark...
    composition_v_inheritance
    Bruce Eckel, author of Thinking In Java, has this to say about composition vs. inheritance:
    When deciding between inheritance and composition, ask if you need to upcast to the base type. If not, prefer composition (member objects) to inheritance. This can eliminate the perceived need for multiple base types. If you inherit, users will think they are supposed to upcast.
    Choose composition first when creating new classes from existing classes. You should only used inheritance if it is required by your design. If you use inheritance where composition will work, your designs will become needlessly complicated.
    Bill Venners: Composition versus Inheritance
    Use inheritance (of implementation) only when the class satisfies the following criteria:
    1) "Is a special kind of," not "is a role played by a";
    2) Never needs to transmute to be an object in some other class;
    3) Extends rather than overrides or nullifies superclass;
    4) Does not subclass what is merely a utility class (useful functionality you'd like to reuse); and
    5) Within PD: expresses special kinds of roles, transactions, or things.
    -- from Java Design: Building Better Apps and Applets (2nd Edition), by Peter Coad and Mark Mayfield

  • Why is sizeof operator not in java ?

    Hello friends..
    I am having one doubt.
    Why is sizeof operator not in java ?
    Can anybody please help ?
    Thanks and Regards
    Rohit.

    An object often refers to other objects. These object may or may not have multiple references (so counting them more than once is not accurate) The actual amount of memory used is often greater than you might expect if you are used to C/C++. The system also uses memory in sometime unpredicable ways. Many methods create transient objects adding to your memory requirement. Shared libraries, the stack, the JVM itself do not appear in the heap size but use memory. Files accessed by the application can be significantly effect the desirable file cache size.
    The only real way to determine your application's memory requirement is to actively test the application, anything else is just guess work.

  • Implementation of multiple inheritence

    hi
    i am goutam.how can we implement multiple inheritence in java.and how two super classes can be inherited in one sub class

    keep it to one thread, please!

  • Best approach to append multiple Access tables together using java?

    Hello,
    I've been given the task of retrieving data from a collection of Access files and storing them in a MySQL database. The program I wrote works fine, but the problem is that the data is broken up by months and not years. I need access to a years worth of data for my calculations to be accurate.
    Therefore, I need to merge all the tables from different databases(files) for one year(12 tables).
    All the tables are identical, just different values for different days.
    I know how to manually append one table to another in MS Access, but that is too time consuming.
    I was thinking of querying all the data of each month and merging all the result sets into one collection to be later inserted into a new MySQL table.
    Any insight of how to do this efficiently would be greatly appreciated.

    maccartee wrote:
    I wrote a java class that will cycle through each Access file, executing a query to select all the rows in the table I need and insert them into a text file. The problem is that the sql query I use works in mysql but not access:
    SELECT * into OUTFILE 'C:\\TableDump.txt' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' FROM 8227;
    You can't write such a thing in Access.
    I get the following when I run it:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Query input must contain at least one table or query.
    I think Access is telling you the right answer: it won't accept that statement.
    8227 is the name of table I want.You named your table '8227'? Oh, my.
    I'm not too familiar with Access, but I thought I could run valid SQL queries?You're not too familiar with SQL. This is only valid in MySQL.
    Why insist on doing this in Java? There's a better way to do this. Save all the Access files as .csv output and import those into MySQL. Java's not the way to go here.
    %

  • Is multiple inheritence is possible in sap?

    can any one help me?
    is multiple inheritence possible in sap ?
    and is one class can extend multiplre interfaces??

    Hi,
            Multiple inheritance as a concept is not allowed in ABAP Objects. But the effect and behaviour that you get by multiple inheritance is acheviable in ABAP objects with the help of interfaces. As follows.
    An interface can inlcude more than one interface, that is an interface can extend more than one interface. Now if you have say interface1, interface2 and interface3.
    interface4 can be declared to include all three other interfaces. And you class can include this interface4 in its interfaces tab.
    Due to this your class gets the behviour(methods) that is defined in all ther interfaces. You can assign an object of this class to a reference of any one of these four interfaces. So one object can react to method calls on four different interfaces which is what you want to achevie in multiple inheritance.
    Regards,
    Sesh

  • Why use customized / particular exceptions instead java.lang.Exception

    Hi,
    Do any of you guys know where can I find a theorical statement / explanation about why use particular / customized exceptions instead java.lang.Exception? I am aware that it consumes more resources and becomes a heavier object, as well as the clearness when coding and all that stuff; however, my boss wants to see a tech document where all this is clearly stated. Any resource over there?
    Regards

    It is better to throw specific--or at least module- or
    package-specific--excpetions, rather than Exception,
    because then the caller knows what to expect. However,
    if you declare "throws Exception", the caller can
    still catch IOException, SQLException, etc.,
    separately. He'll just have to be a really good
    guesser as to which ones he should catch.True.
    Also, there's no point in declaring "throws
    NullPointerException." Any method can throw it without
    declaring it. If you generate your own NPE (or other
    unchecked exception) inside the method, then you
    should document it in the javadoc comments, but you
    don't need to put it in the throws clause. It doesn't
    do any harm, but it's redundant and cluttersome.It was an example and I wasn't feeling too creative....excuse me. ;-) But yeah, I've never thrown NPE ever.
    I'm assuming overhead caused by extending classes.At
    the worst, it would be miniscule, or so I wouldthink.
    What overhead is created by extending classes?Hmm, I was under the impression that a class the extended another class, inherited all of the other classes data (variables, etc.). Hence, you get something like this:
    SuperClass1 + SubClass1 + SubClassOfSubcCass1 = Memory usuage for SubClassOfSubClass1.
    Since adding postivie number will always end up increasing data, SubClassOfSubClass1 will use more dtat than SuperClass1.
    Am I wrong?

  • WHY can't Apple get their Java to work with Homestead SiteBuilder??!! Please someone work this out :(

    WHY can't Apple get their Java to work with Homestead SiteBuilder??!! Please someone work this out  

    Is Java enabled in Safari / Preferences - Security?
    Try the SiteBuilder help center.
    Perhaps using a different browser may help.
    Try Firefox or Chrome.
    Mozilla Firefox Web Browser — Free Download
    Google Chrome - The web is what you make of it

  • Why do we need downcasting in Java? What is the use of it?

    Why do we need downcasting in Java? What is the use of it?

    here's an example of a valid downcast.
    class Dog {}
    class Dogma extends Dog {}
    class Dogmatic extends Dog {}
    Dog dogwood = new Dogma(); // a Dogma object is upcast to a Dog
    Dogma bush = (Dogma) dogwood; // a Dogma object is downcast from a Dog
    You cannot upcast a Dogmatic to a Dog and then downcast it to a Dogma. You also cannot downcast a Dog to a Dogma. In the working example, above, the dogwood references a Dogma, so you can downcast the Dogma.
    and one more example
    If you have a class hierarchy where class B extends class A (B is a specialization of A) you can use B in the place of A since B supports all the operations that B does. This is called polymorphism.
    When you use an object of type B in place of A you actually do a up-cast, meaning you make the object of type B look like an object of type A (a less specific class type).
    What you are asking about is down-casting which is making an object be of a more specific type, i.e. transforming an object of type A to type B. Is is only allowed if the object was actually created as a type B.
    This is allowed (line 2 is a down-cast):
    A a = new B();
    B b = (B)a;

  • Why do we need to import 'java.lang.annotation' ?

    Hi All,
    Since java.lang.* is the default package for all java file, Why do we need to import 'java.lang.annotation' separately?
    Thanks in advance..
    Regards
    Karthikeya V

    Karthikeya wrote:
    Hi All,
    Since java.lang.* is the default package for all java file, Why do we need to import 'java.lang.annotation' separately?
    Thanks in advance..
    Regards
    Karthikeya VLet me explain that differently: packages on disc usually form a directory structure (but it is not a rule, elements of the same package structure can come from different jars). BUT, this does not automatically mean that packages to Java form some kind of hierarchy as well - they don't. java.lang and java.lang.annotation are simply two completely different, unrelated packages.

  • HT5246 Why, if I have not installed Java, is Flashback malware a threat on my mac?

    Why, if I have not installed Java, is Flashback malware a threat on my mac?

    Older variants of Flashback did not rely on Java, and if you upgraded to Lion after becoming infected with a Java variant, you would still be infected even without Java.  (The malware itself does not need Java, only the installer for recent variants does.)

  • Multiple Inheritence/Const Compiler bug

    I'm encountering what appears to be a bug when mixing multiple inheritence & const/non-const methods. The compiler (WorkShop 6 Update 2) is accepting the following ill-formed code :
    class Base1 {
    int a; //If Base1 is empty, the problem doesn't appear.
    //A virtual function elicits the bug as well.
    class Base2 {
    public:
    void mutator() { //non-const method   
    class Derived : public Base1, public Base2 {
    class Foo {
    private:
    Derived my_derived;
    public:
    void f() const {
    my_derived.mutator();
    int main (int argc, char* argv[])
    Foo my_foo;
    my_foo.f();
    Note how f() in class Foo is const, yet attempts to call mutator(), a non-const method that my_derived gets via inheritence to Base2. This is ill formed and should, I believe, yield a compiler error. If the code is just subtly changed, the correct error will appear. For instance, if Base1 is empty, the appropriate error appears. Alternatively, if Base2 appears before Base1 in Derived's inheritence list, then the appropriate error appears.
    Is this a known problem? Is there a patch available? I'm very concerned that this bug is allowing const-incorrect code to be developed unknowingly, as it has in the project I'm involved in.
    Thanks in advance for giving this your attention!
    David Michael

    The bug report hasn't been filed yet. If you have contract with Sun, please follow the service channel to file the report. Otherwise, I can do it for you. Please provide:
    - O/S version
    - Architecture
    Please notice that if you don't have contract with sun, the bug might be in a low priority.
    - Rose

Maybe you are looking for

  • Processo de Industrialização

    Boa tarde pessoal!! Gostaria da ajuda de vcs no meu cenário...estou criando um processo de industrialização via SD onde o primeiro processo é a entrada de matéria prima, na qual criei com base em um processo de devolução, esse processo referencia o s

  • How can I import an ics calendar file to my iPAd2

    I want to import my Windows calendar into my iPad2. I've tried using the ics file which is mentioned in the manual but no joy. What can I do?

  • Variable instantiation not working

    Hello all, I have the most weird problem: Inside a custom component based on list, I'm getting an arrayCollection from a RemoteObject, and after I want to create a new array where I set (in the client) which elements are, or are not selected). In the

  • CIN details in vendor report S_ALR_87012089

    Dear Experts , The report S_ALR_87012089 is used for tracking the changes made in vendor master . We  maintain the vendor CIN details in the CIN tab in vendor master , but the said report doesnt trace the changes made in vendor master CIN tab . Pls a

  • IPSEC issue in Cisco IAD 2431

    Hello all, I cam across something when i was troubleshooting IPSEC VPN connections between two Cisco IAD 2431s. Here is a snapshot of config on one of the routers: crypto map vpnmap 6 ipsec-isakmp description To_Grovecity set peer X.X.X.X set transfo