Inheritance vs Interfaces

Hi,
I know that interfaces are used to create an empty class which cannot be instantiated as it is not implemented. The user will have to eventually implement all or some of the methods defined. Now my problem lies here...cant' the user simply use inheritance and then override the method/s which he/she wants to behave differently from the parent class? I mean whats the reason/s for having interfaces, and what are the differences between inheritance and interfaces?
I apologize for asking such a simple question but still cant understand the basic concept after I Googled it out.
Thanks for your attention
Dave
Edited by: BeginnerDave on Aug 19, 2009 6:12 AM

BeginnerDave wrote:
I know that interfaces are used to create an empty class which cannot be instantiated as it is not implemented.Sort of, but I prefer to think of it as a type rather than a class. The Interface defines a type and the methods that must be implemented for it. A blueprint, if you like.
The user will have to eventually implement all or some of the methods defined.Actually, in order for it to be instantiated, all methods will have to be implemented.
Now my problem lies here...cant' the user simply use inheritance and then override the method/s which he/she wants to behave differently from the parent class?Yup. But not everything fits neatly into an inheritance structure.
I mean whats the reason/s for having interfaces, and what are the differences between inheritance and interfaces?Lots; but just for starters: A class can implement many interfaces, but it can have only one superclass.
So basically, you go for interfaces when you want to share empty classes....and inheritance when you want to modify class type ...I think you need to read a bit more about this.
Inheritance is only applicable when one class is a specialized form of another: eg:
Shape-->Circle
Mammal-->Primate-->Human
Product-->Cereal-->CornFlakes
Interfaces can be implemented by any class in any combination, and it then takes on the type of that Interface, which is why it's perfectly legal to say:
List myList = new ArrayList();because List is an interface, and ArrayList is a class that implements List.****
HIH a bit.
Winston
****(BTW, it's better to use generics when defining Lists, but I didn't want to clutter the example).

Similar Messages

  • Java inheritance and interface code help required

    please help me I need your 30 mins only,,, working on assignment and I am trying to understand interface and inheritance might not need even 30 mins, please add me on skype *[deleted by moderator]*
    Or add me on
    yahoo msgr *[deleted by moderator]*
    waiting for your help.
    I have no single person friend or I can ask help from who knows java or programming. pretty much want to learn need a friend who can guide me in java.
    unfortunately have to submit assignment tomorrow.
    Thank you in advance for your time and consideration.
    Akee
    *Edited by moderator: EJP on 10/11/2012 10:38: removed your private contact details. This is a public forum, not a personal help desk. Ask your questions here or not at all.*

    Hi,
    there are lot of thread alredy posted please serach
    check following link
    http://help.sap.com/saphelp_nw04/helpdata/en/ce/1d753cab14a909e10000000a11405a/frameset.htm
    XSLT Mapping:
    http://help.sap.com/saphelp_nw04/helpdata/en/73/f61eea1741453eb8f794e150067930/content.htm
    Java Mapping:
    http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm
    Links of blogs on java mapping...
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
    blog
    /people/sap.user72/blog/2005/03/15/using-xslt-mapping-in-a-ccbpm-scenario
    /people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping(file to xslt mapping)
    /people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners(xslt with java enhancement function)
    Regards,
    Amit

  • 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 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.

  • Inheritance and Interface invocation Query

    interface IProduct{
         void getProductName();            
    abstract class Option implements Product{
                 void exercisePrice();
                 void premiumPaid();
    class Option1 extends Option{
               // Implement all abstract methods defined in Option and IProduct.
    class Option2 extends Option{
         // Implement all abstract methods defined in Option and IProduct.
    class Trade{
               public Trade(IProduct p){
         p.getProductName()   // I can only get this method behaviour.
                    // My Query
                    // I also need to invoke the methods exercisePrice() and premiumPaid() defined in Option1 and Option2
                    // If I use instanceof,the code will get cluttered and ugly.
                                     if p instanceof Option1
                                     Option1 op1 = ((Option1) p);
                                     op1.exercisePrice();
                                      if p instanceof Option2
                                      if p instanceof OptionN
    class TestHarness{
             public static void main(String args[]){
             // Create an option
             Option1 option1 = new Option1();
             // Trade in the product
             Trade trade = new Trade(option1);
             Query:
             The Trade constructor defines IProduct.
             IProduct can be a concrete Bond,Option,CDS,IRS etc.
             How do I get the methods defined in subclasses Option1 and Option2 or for any concrete subclass of IProduct?
             Is there a way of dynamically invoking the methods of the object created?
            Or do I need to change the design.
    }

    It looks to me like you're violating the Liskov Substitution Principle.
    "The LSP says that the users of base classes should not have to do anything special in order to use derivatives."
    - R. MartinThis also violates the Open/Closed principle, because whenever you add a new Option concrete class, you're going to have to update your Trade class (it's not "closed to modification" when the environment around it changes).
    The "fix" is just that its not a good idea to force the polymorphism by using instanceof. You should either:
    1. Get rid of the IProduct interface completely and treat each product type separately.
    2. Reconsider your base class (in this case, IProduct) to see if it really can contain additional behavior applicable to all products.
    The previous post about the visitor pattern is interesting, but I don't see how it applies to this example (perhaps some more light could be shed there by the poster).

  • Inheritance  from interface ans class

    Hi All
    Say I have interface A and class B.
    Now I creating class C extands B implements A
    who is C's super class? the class or the interface?
    Can I write somthing like this?
    A name = new C() or B name = new C()?
    Thank u in advance
    Eyal

    Hi All
    Say I have interface A and class B.
    Now I creating class C extands B implements A
    who is C's super class? the class or the interface?The class, because you said superclass.
    Can I write somthing like this?
    A name = new C() or B name = new C()?
    Thank u in advance
    EyalDo you have access to a compiler? You could try it and see faster than you
    would get an answer from the forum.

  • About Inheritance and interface!

    I have to write a PQueue2 class which implements PriorityQueue interface, also PQueue2 has to extend BinaryHeap,
    so at the top of the PQueue2 I should have this right?
    public class PQueue2 extend BinaryHeap implements PriorityQueue {

    I meant that if PQueue2 extends BinaryHeap
    then it can call directly all the functions in the
    e BinaryHeap right? but it can also add new methods?It's more like the public and protected methods in BinaryHeap are also the methods of PQueue2. If I create a PQueue2 outside of either class, I can call any public method defined in BinaryHeap on PQueue2.
    the extends keyword creates an "is a" relationship between a class and the class it extends. Every PQueue2 instance is an instance of BinaryHeap (but not the other way around.)

  • Inheritance? interface?

    Hi, I have used inheritance incorrectly... could you point out how do I fix it please? My code looks like this:
    public abstract class FeatureSpace{
      public void methodA(){
    public class FeatureSpaceImplA{
      public void methodB(){
    public class FeatureSpaceImplB{
      public void methodC(){
    public abstract class FeatureSpaceBuilder(){
      //This method takes an article content(String), analyse the article and create its
      //feature space; the feature are stored in the method argument "space". 
      //Instead of returning a new FeatureSpace by the method itself,
      //I'd like to pass a FeatureSpace object to the method, and modify it by the method;
      //the reason is this method will be used iteratively, but eventually build only *one* FeatureSpace.
      // Consider given a corpus of 100 articles, this method will be called
      //100 times, building Features for each article, but store features in a
      // single FeatureSpace as for the whole corpus. So instead of creating
      // and returning then merging a new FeatureSpace each time, I just
      // pass the single FeatureSpace object to the method every iteration, and
      //modifies it.
      abstract void buildFeatureSpace(String article, FeatureSpace space);
    public class FeatureSpaceBuilderImplA(){
      public void buildFeatureSpace(String article, FeatureSpaceImplA space){
    public class FeatureSpaceBuilderImplB(){
      public void buildFeatureSpace(String article, FeatureSpaceImplB space){
    }As you see, I need to use inheritance on the method arguments, but the compiler complains
    "public abstract void buildFeatureSpace(String article, FeatureSpace space)"
    needs to be implemented in both sub-classes.
    I have defined separate methods in each sub class as:
    ""public abstract void buildFeatureSpace(String article, FeatureSpaceImplB space)"
    "public abstract void buildFeatureSpace(String article, FeatureSpaceImplA space)"
    Where "FeatureSpaceImplA" and "FeatureSpaceImplB" extends "FeatureSpace". But this doesnt work. I need to use specifc "FeatureSpace" in above two methods because their behaviors are different.
    I feel that I may have done this in totally wrong way.... can you give me some advice pleas, many thanks!

    Ah sorry but thanks for pointing out! Please ignore the code below
    "public abstract class FeatureSpaceBuilder(){",
    I cannot re-edit it, but they should go like this:
    public abstract class FeatureSpaceBuilder{
      //This method takes an article content(String), analyse the article and create its
      //feature space; the feature are stored in the method argument "space". 
      //Instead of returning a new FeatureSpace by the method itself,
      //I'd like to pass a FeatureSpace object to the method, and modify it by the method;
      //the reason is this method will be used iteratively, but eventually build only *one* FeatureSpace.
      // Consider given a corpus of 100 articles, this method will be called
      //100 times, building Features for each article, but store features in a
      // single FeatureSpace as for the whole corpus. So instead of creating
      // and returning then merging a new FeatureSpace each time, I just
      // pass the single FeatureSpace object to the method every iteration, and
      //modifies it.
      abstract void buildFeatureSpace(String article, FeatureSpace space);
    public class FeatureSpaceBuilderImplA extends FeatureSpaceBuilder{
      public void buildFeatureSpace(String article, FeatureSpaceImplA space){
    public class FeatureSpaceBuilderImplB extends FeatureSpaceBuilder{
      public void buildFeatureSpace(String article, FeatureSpaceImplB space){
    }

  • Set an attribute inherited by an interface

    Hello,
    I've got a problem setting an attribute, so i appreciate your help or a link to a solution in advantage.
    Situation: I've created an interface hosting some attributes. I've created an business object inheriting the interface. Now i try to set the value of the interface's attributes by invoking an interface's method (handing over the standard container of the business object). Unfortunatly, as result there are created new container elements instead of setting the interface's attributes.
    How can i fix this problem?
    Thanks, Stephan

    I think you have misunderstood a thing or two with respect to enhancing/developing BOR object types. You should definitely implement the attributes. It should always be the attribute implementation code that sets the container value - even if it is technically possible to do it in some other way, this is bad practice and not upwards compatible if SAP enforces a more strict interface check (same problem that applies to undeclared parameters for methods).
    Using a method to set attribute values is just stupid. It requires an extra step in the workflow, and it is not necessary since attributes will be automatically populated whenever they are needed. Additionally, if your attributes were only populated after a method call, you wouldn't be able to use them in customized inbox views, or in workflow start conditions.
    So, I suggest you implement each of the attributes, and let them call a common subroutine in your implementation program which sets the data (object-whatever-whatever). Then each attribute implementation just makes a perform call, and calls the SWC_SET_ELEMENT macro. Your subroutine can be as sophisticated or unsophisticated as you need/wish - e.g. checking whether there is any need to refresh the values if there is a lot involved in finding the values.

  • Multiple inheritance in tagging interface? Is it possible?

    I saw a code somewhere that goes like this:
    public interface Node extends Serializable, Clonable
    ...Is it possible? I know that Java doesn't allow multiple inheritance and that Serializable and Clonable are tagging interfaces where no method must be implemented by the programmer.

    KamenRiderZX wrote:
    I know that Java doesn't allow multiple inheritanceMore exactly: Java doesn't allow multiple inheritance of implementations. Inheriting multiple interfaces ("implements" for classes, "extends" for interfaces) is fine 'though.

  • Interfaces instead of multiple inheritance?

    I've read that "The Java programming language does not permit multiple inheritance , but interfaces provide an alternative."
    But I also read contradictory information-There are no method bodies in an interface.
    Java interfaces only contain empty methods? Apparently, if I want to share a method among classes, I have to re-write the methods in each class that implements the interface. That doesn't seem at all like multiple inheritance. Am I missing something?
    It seems that I will have to cut and paste the implementation code from one class to another, and if I change the methods, I have to cut and paste it all over again.
    I've read that interfaces save a lot of time re-writing methods, but how?
    Does this really provide the same capabilities as multiple inheritance, or am I missing something?
    Thanks,
    Pat

    Pat-2112 wrote:
    I've read that "The Java programming language does not permit multiple inheritance , but interfaces provide an alternative."
    But I also read contradictory information-There are no method bodies in an interface. That's not contradictory.
    Inheritance is about type, which interfaces provide. It is NOT about sharing code, which is all that's lacking by not having multiple inheritance of implementation.
    Java interfaces only contain empty methods? Apparently, if I want to share a method among classes, I have to re-write the methods in each class that implements the interface. That doesn't seem at all like multiple inheritance. Am I missing something? Yup. You're missing the point of inheritance, and the fact that delegation allows you to use an implementation defined in one class in another class.
    It seems that I will have to cut and paste the implementation code from one class to another, Nope.
    public interface Cowboy {
      void ride();
      void draw();
    public interface Artist {
      void sculpt();
      void draw();
    public interface CowboyArtist extends Cowboy, Artist {
    public class CowboyImpl implements Cowboy {
      public void ride() {
       System.out.println("Giddyup!");
      public void draw() {
        S.o.p("Bang!");
    public class ArtistImpl implements Artist {
      public void sculpt() {
        S.o.p("Demi Moore in Ghost. Yum!");
      public void draw() {
        S.o.p("Sketch a picture of a gun.");
    public class CowboyArtistImpl implements CowboyArtist { // or implements Cowboy, Artist
      private final Cowboy cowboy = new CowboyImpl();
      private final Artist artist = new AristImpl();
      public void ride() {
        cowboy.ride();
      public void sculpt() {
        artist.sculpt();
      public void draw() { // uh-oh, what do we do here?
        artist.draw();
        cowboy.draw();
    }The draw method is not relevant to this particular question. It's an example of one of the problems with MI, and I just included it since it usually comes up int these discussions anyway. Ride and sculpt demonstrate the point about delegation.

  • Inheritance vs. Interface

    Hi,
    I have a general question to ask. I generally know the difference between inheritance vs. interface. But recently I came upon a simple class that I like to get people opinion on... We have a 2 person team on this project and we sort of have a slight disagreement as to which is a better approach.
    We had 2 different classes:
    // This class is used along with some other object which will provides the
    // name of the operand.
    public class Filter {
       String dataType;      // STRING, INTEGER, DATE and etc.
       String operator;
       String values;
    public class AttributeFilter {
       Attribute attribute;    // Another class that includes the name and dataType
       String operator;
       String values;
    }We are thinking to refactoring these classes, and there are 2 approaches. First, using the inheritance to have a superclass where the other classes inherit from it:
    public class FilterSuper {
       String operator;
       String values;
    }Second, using the interface like so:
    public Interface FilterInterface {
       public String getName();
       public String getDataType();
       public String getOperator();
       public String getValues();
    }I tend to like the interface approach, but I like to get your opinion on this also.
    Thanks...
    --chung                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    > there are 2 approaches.
    There are more than just two! :o)
    Generally speaking, interfaces should describe behavior rather than define a series of methods to expose state. The case you describe doesn't seem to be an exception; I would expect a "Filter" to actually filter something. In my opinion, you'd be better off defining a Filter interface with a method called "filter()" or "execute()" (or something similar) that takes as a parameter some type on which to execute the filter.
    This functionality is often built as a chain of responsibility; have a look at the following:
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html
    ~

  • Abstract class Vs interface

    Hi,
    I have to buid a report in ECM with complete details of the engineering as well as production. This include workflow as well as various fucntionality depends upon the criterion and user's event.
    I am implementating in OOPS and I Want to know that when I should use the Abstract class and when interface  ?
    Because as per me both serve the same purpose. Kindly send me the exact difference so that i can efficiently use the same.
    Thanks
    Prince

    When inheriting A Interface We have to inherit all the methods of the Interface there's no other option whereas with abstract classes we can inherit the members that we are in need of.
    Just the interface has to have body of the method and the method is to be used by the classes inheriting it. Whereas in the case of Abstract Class it can have declarations (Other than the abstract method) and it can be further extended in the classes inheriting the Abstract Class.
    Interface contains all abstract methods,all methods compulsory implemented by particular class, interface does not contain Constructor
    abstract classes are designed with implemantion gaps for sub-class to fill in.
    interfaces are sintacticlly similar to classes but they lack insance variables & methods.
    abstract classes can also have both abstract methods & non-abstract methods. where as in interface methods are abstract only, & variables are implicitly static&final
    regards
    Preetesh

  • A question about inheritance and overwriting

    Hello,
    My question is a bit complicated, so let's first explain the situation with a little pseudo code:
    class A {...}
    class B extends A{...}
    class C extends B {...}
    class D extends C {...}
    class E extends B {...}
    class F {
      ArrayList objects; // contains only objects of classes A to E
      void updateObjects() {
        for(int i = 0; i < objects.size(); i++)
          A object = (A) objects.get(i); // A as superclass
         update(A);
      void update(A object) { ... }
      void update(B object) { ... }
      void update(D object) { ... }
    }My question now:
    For all objects in the objects list the update(? object) method is called. Is it now called with parameter class A each time because the object was casted to A before, or is Java looking for the best fitting routine depending on the objects real class?
    Regards,
    Kai

    Why extends is evil
    Improve your code by replacing concrete base classes with interfaces
    Summary
    Most good designers avoid implementation inheritance (the extends relationship) like the plague. As much as 80 percent of your code should be written entirely in terms of interfaces, not concrete base classes. The Gang of Four Design Patterns book, in fact, is largely about how to replace implementation inheritance with interface inheritance. This article describes why designers have such odd beliefs. (2,300 words; August 1, 2003)
    By Allen Holub
    http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html
    Reveal the magic behind subtype polymorphism
    Behold polymorphism from a type-oriented point of view
    http://www.javaworld.com/javaworld/jw-04-2001/jw-0413-polymorph_p.html
    Summary
    Java developers all too often associate the term polymorphism with an object's ability to magically execute correct method behavior at appropriate points in a program. That behavior is usually associated with overriding inherited class method implementations. However, a careful examination of polymorphism demystifies the magic and reveals that polymorphic behavior is best understood in terms of type, rather than as dependent on overriding implementation inheritance. That understanding allows developers to fully take advantage of polymorphism. (3,600 words) By Wm. Paul Rogers
    multiple inheritance and interfaces
    http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html
    http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html
    http://www.artima.com/intv/abcs.html
    http://www.artima.com/designtechniques/interfaces.html
    http://www.javaworld.com/javaqa/2001-03/02-qa-0323-diamond_p.html
    http://csis.pace.edu/~bergin/patterns/multipleinheritance.html
    http://www.cs.rice.edu/~cork/teachjava/2002/notes/current/node48.html
    http://www.cyberdyne-object-sys.com/oofaq2/DynInh.htm
    http://www.gotw.ca/gotw/037.htm
    http://www.javajunkies.org/index.pl?lastnode_id=2826&node_id=2842
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=001588
    http://pbl.cc.gatech.edu/cs170/75
    Downcasting and run-time
    http://www.codeguru.com/java/tij/tij0083.shtml
    type identification
    Since you lose the specific type information via an upcast (moving up the inheritance hierarchy), it makes sense that to retrieve the type information ? that is, to move back down the inheritance hierarchy ? you use a downcast. However, you know an upcast is always safe; the base class cannot have a bigger interface than the derived class, therefore every message you send through the base class interface is guaranteed to be accepted. But with a downcast, you don?t really know that a shape (for example) is actually a circle. It could instead be a triangle or square or some other type.
    To solve this problem there must be some way to guarantee that a downcast is correct, so you won?t accidentally cast to the wrong type and then send a message that the object can?t accept. This would be quite unsafe.
    In some languages (like C++) you must perform a special operation in order to get a type-safe downcast, but in Java every cast is checked! So even though it looks like you?re just performing an ordinary parenthesized cast, at run time this cast is checked to ensure that it is in fact the type you think it is. If it isn?t, you get a ClassCastException. This act of checking types at run time is called run-time type identification (RTTI). The following example demonstrates the behavior of RTTI:
    //: RTTI.java
    // Downcasting & Run-Time Type
    // Identification (RTTI)
    import java.util.*;
    class Useful {
    public void f() {}
    public void g() {}
    class MoreUseful extends Useful {
    public void f() {}
    public void g() {}
    public void u() {}
    public void v() {}
    public void w() {}
    public class RTTI {
    public static void main(String[] args) {
    Useful[] x = {
    new Useful(),
    new MoreUseful()
    x[0].f();
    x[1].g();
    // Compile-time: method not found in Useful:
    //! x[1].u();
    ((MoreUseful)x[1]).u(); // Downcast/RTTI
    ((MoreUseful)x[0]).u(); // Exception thrown
    } ///:~
    As in the diagram, MoreUseful extends the interface of Useful. But since it?s inherited, it can also be upcast to a Useful. You can see this happening in the initialization of the array x in main( ). Since both objects in the array are of class Useful, you can send the f( ) and g( ) methods to both, and if you try to call u( ) (which exists only in MoreUseful) you?ll get a compile-time error message.
    If you want to access the extended interface of a MoreUseful object, you can try to downcast. If it?s the correct type, it will be successful. Otherwise, you?ll get a ClassCastException. You don?t need to write any special code for this exception, since it indicates a programmer error that could happen anywhere in a program.
    There?s more to RTTI than a simple cast. For example, there?s a way to see what type you?re dealing with before you try to downcast it. All of Chapter 11 is devoted to the study of different aspects of Java run-time type identification.
    One common principle used to determine when inheritence is being applied correctly is the Liskov Substitution Principle (LSP). This states that an instance of a subclass should be substitutible for an instance of the base class in all circumstances. If not, then it is generally inappropriate to use inheritence - or at least not without properly re-distributing responsibilities across your classes.
    Another common mistake with inheritence are definitions like Employee and Customer as subclasses of People (or whatever). In these cases, it is generally better to employ the Party-Roll pattern where a Person and an Organization or types of Party and a party can be associated with other entities via separate Role classes of which Employee and Customer are two examples.

  • Doubt on Multiple Inheritance

    Hi all,
    I am confused by the java statement that "By using interface we can achieve multiple inheritance bcoz java doesn't support Multiple inheritance".
    Yes.Ok java doent support Multiple inheritance. Now we know that inheritance means that "one object acquires the property of another object".
    So how can it is possible achieve Multiple inheritance by interface.
    Interface that contains just undefined methods like below code.
    interface Member1
         public void eye();
         public void nose();
         public void mouth();
    interface Member2 extends member1
         public void neck();
         public void hand();
         public void stomach();
    interface Member3 extends Member1,Member2
         public void leg();
    class Man implements Member3
         public man()
         Member3 ref=new Man();
         // Here Implements all 7 methods.
    Is the above code defines multiple Inheitance?
    undefined methods are eye,nose,mouth,neck,handand stomach are fall in Interface Member3 .Yes. But Inheritance means that one object acquires the property of another object.Property means that code and data.
    In here, there is no code just declarations of method which is not to be a code .
    So How can we say interface achieve multiple inheritance.
    Please any one explain and clear my doubt with simple example.
    with cheers,
    G.GandhiRaj.

    Multiple inheritance is about aquiring both behavior and attributes from two or more sources. A lot of times, this "is a" relationship is confused with "has a" relationships.
    For example, a Book "has a" Page. A Book "is a" Publication. So multiple inheretance in this instance would come from stating that a Book "is a" Publication and "is a" PaperProduct. In this example, you could redesign your model and state that a PaperProduct inherits from Publication. However, a Book doesn't have to be limited to being a PaperProduct, it can also be an ElectronicProduct, thus inhereting attributes and behaviors from this new class as well. In essence, the Book can exist in two forms simulataneously (as many actually do). So you still have the need for multiple inheritance - perhaps.
    Interfaces define the behavioral aspects of multiple inheritance. You loose the aquisition of attributes from base classes. In many cases this is acceptable. For the first time I recently found a true need for multiple inheritance in one fo my Java apps. Some would say that my data model is poorly designed then. So I tried restructuring the model and that solve the problem.
    It is probably a good idea to completely understand your data model from many dimensions first before resorting to the copying of attributes like I almost did. Don't be locked into a design too quickly. Be willing to change your mind and you will probably find a solution that works.

Maybe you are looking for

  • VPRS Cost Condition type

    Hello, I have copied VPRS cost condition type & created a new cost condition type ZABC for the purpose of recognizing cost for a project. When i create sales order VPRS & ZABC cond types are getting populated  in sales order with correct cost but whe

  • Mail Triggering point

    hello, we configured an EDI output for PO. when ever this EDI output triggers one mail communication is being sent to vendor. Problem is this was done long before and we could not find from where it is being triggered. we need to change the message b

  • E7 always restart while making call with Bluetooth...

    Has anybody experienced a problem that you can not make calls when qwerty keyboard is in use and Bluetooth to headset is activated because phone makes every time restart while setting up the voice call. It just first indicates that "disconnecting Blu

  • What is error code 3328

    What is error code 3328

  • OS10.4 will no longer connect to internet via dial-up, but it will in OS9.2

    Over the last week I noticed it was taking longer and longer to make a connection to the internet, then this evening it just would not connect at all in OS10.4. A message comes up and says there is a modem error to check all settings and try again. F