HI  question on inheritance

Why abap does not support multiple inheritance

shanthi,
check the below threads.... same question discussed before also
multiple inheritance
Re: Does ABAP Obj. supports multiple or multilevel inheritence
If you find what ever u r looking for please close the thread...... if u need further info lemme know
~~Guduri

Similar Messages

  • Question regarding Inheritance.Please HELP

    A question regarding Inheritance
    Look at the following code:
    class Tree{}
    class Pine extends Tree{}
    class Oak extends Tree{}
    public class Forest{
    public static void main(String args[]){
      Tree tree = new Pine();
      if( tree instanceof Pine )
      System.out.println( "Pine" );
      if( tree instanceof Tree )
      System.out.println( "Tree" );
      if( tree instanceof Oak )
      System.out.println( "Oak" );
      else System.out.println( "Oops" );
    }If I run this,I get the output of
    Pine
    Oak
    Oops
    My question is:
    How can Tree be an instance of Pine.? Instead Pine is an instance of Tree isnt it?

    The "instanceof" operator checks whether an object is an instance of a class. The object you have is an instance of the class Pine because you created it with "new Pine()," and "instanceof" only confirms this fact: "yes, it's a pine."
    If you changed "new Pine()" to "new Tree()" or "new Oak()" you would get different output because then the object you create is not an instance of Pine anymore.
    If you wonder about the variable type, it doesn't matter, you could have written "Object tree = new Pine()" and get the same result.

  • One very basic question about inheritance

    One very basic question about inheritance.
    Why we need inheritance?
    the benefit of inheritance also achieve by creating instance of base class using it in other class instead of extending the base class.
    Can any one please explain why we are using inheritance instead of creating object of base class????

    SumitThokal wrote:
    One very basic question about inheritance.
    Why we need inheritance?
    the benefit of inheritance also achieve by creating instance of base class using it in other class instead of extending the base class.
    Can any one please explain why we are using inheritance instead of creating object of base class????What did you find out when you looked on Google?
    One example of inheritance comes in the form of a vehicle. Each vehicle has similarities however they differ in their own retrospect. A car is not a bus, a bus is not a truck, and a truck is not a motorbike. If you can define the similarities between these vehicles then you have a class in which you can extend into either of the previous mentioned vehicles. Resulting in a reusable class, dramatically reduces the size of code, creates a single point of definition, increases maintainability, you name it.
    In short there are thousands of benefits from using inheritance, listing the benefits could take a while. A quick Google search should give you a few hundred k if not million links to read.
    Mel

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

  • A little question about inheritance

    Can someone explain this to me?
    I have been reading about inheritance in Java. As I understand it when you extend a class, every method gets "copied" to the subclass. If this is so, how come this doesn't work?
    class inherit {
        int number;
        public inherit(){
            number = 0;
        public inherit(int n){
            number = n;
    class inherit2 extends inherit{
        public inherit2(int n, int p){
            number = n*p;
    class example{
        public static void main(String args[]){
            inherit2 obj = new inherit2();
    }What I try to do here is to extend the class inherit with inherit2. Now the obj Object is of inherit2 class and as such, it should inherit the constructor without parameters in the inherit class or shouldn't it ??? If not, then should I rewrite all the constructors which are the same and then add the new ones??

    I believe you were asking why SubClass doesn't have the "default" constructor... after all, shouldn't SubClass just have all the contents of SuperClass copy-pasted into it? Not exacly. ;)
    (code below... if you'd like, you can skip the first bit, start at the code, and work your way down... depending on if you just started, the next bit may confuse rather than help)
    Constructors are special... interfaces don't specify them, and subclasses don't inherit them. There are many cases where you may not want your subclass to display a constructor from it's superclass. I know this sounds like I'm saying "there are many cases where you won't want a subclass to act exactly like a superclass, and then some (extend their functionality)", but its not, because constructors aren't how an object acts, they're how an object gets created.
    As mlk said, the compiler will automatically create a default constructor, but not if there is already a constructor defined. So, unfortunatley for you, there wont be a default constructor made for SubClass that you could use to create it.
    class SuperClass { //formerly inherit
    int number;
    public SuperClass () { //default constructor
    number = 0;
    public SuperClass (int n) {
    number = n;
    class SubClass extends SuperClass { //formerly inherit2
    //DEFAULT CONSTRUCTOR, public SubClass() WILL NOT BE ADDED BY COMPILER
    public SubClass (int n, int p) {
    number = n*p;
    class Example {
    public static void main(String [] args) {
    //attempted use of default constructor
    //on a default constructorless subclass!
    SubClass testSubClass = new SubClass();
    If you're still at a loss, just remember: "Constructors aren't copy-pasted down from the superclass into the subclass!" and "Default constructors aren't added in if you add your own constructor in" :)
    To get it to work, you'd have to add the constructor you used in main to SubClass (like doopsterus did with inheritedClass), or use the constructor you defined in SubClass for when you make a new one in main:
    inherit2 obj = new inherit2(3,4);
    Hope that cleared things up further, if needed. By the way, you should consider naming your classes as a NounStartingWithACapital, and only methods as a verbStartingWithALowercase

  • Question about inheritance

    I'm attempting to write Monopoly and I'm having some inheritance problems. Every space on the board is first and foremost of type BoardSpace however some of them are of type Property which extends BoardSpace and some are of type Chance/Community which also extend BoardSpace etc. Depending on what type of space it is something different happens. Right now heres how a couple of classes look. I'm having a problem where if I land on a space that doesn't define its own action method, it defaults to the BoardSpace action method as it should yet it goes into that if statement even when it clearly shouldn't be. Like if I land in jail, it will still go into that if statement, and it will print Jail (3 times). Is this something funky with inheritance?
    BoardSpace:
    public class BoardSpace extends JPanel
         Location loc;
         String name;
         public BoardSpace(String s, Location l)
              loc = l;
              name = s;
         public void action(Player p)
              if(name.equals("Go"));//If name is "go" how can it also be "jail" ?
                   System.out.println(name);
                   System.out.println(this.name);
                   System.out.println(p.spot.name);
                   p.money+=200;
    }Property:
    import javax.swing.*;
    public class Property extends BoardSpace
         Player owner = null;
         public Property(String s, Location l)
              super(s,l);
         public void action(Player p)
              if(owner!=null && owner!=p)
                   JOptionPane.showMessageDialog(this,"You landed on "+this.name+".\n This property is owned by Player" +owner.number+".\n You owe $5");
              else
                   JOptionPane.showInputDialog("Buy?");
    }

    duckbill wrote:
    Hint: you can launch JOptionPane dialogs without a single panel, frame etc...
    #You can also launch dialogs with panels, frames, etc... but without subclassing Property from JPanel
    Edited by: DrLaszloJamf on Oct 3, 2007 12:42 PM

  • Question regd Inheritance. Please read

    In Inheritance,when a subclass extends a Superclass,
    the subclass is a specialized version of the superclass.Right?
    class B extends A{
    So,B is a specialized version of A.
    Supposing that class B also implements an Interface:
    class B extends A implements iFace{
    So now:
    Is B a specialized version of class A or a specialized version of an interface?
    Please can anyone answer?

    nope ist not a specialization od the interface. there right terminus would be class A is an implementation of the interface.
    interfaces have no behavoir, the are more sort of a method template which has to be implemented by another class. so something that has no behavoit cannot be specialized.

  • Question about inheritance and  casting

    according to the java api it said Calendar() is a super-class of GregorianCalendar(). with that said it means GC inherits all members of C(). i hope everyone agrees with me here.
    why is it necessary to do this:
    Calendar c = new GregorianCalendar();//by the way this is called implicit casting per the java tutorial.if GC inherits everything from C, and if you need members from both classes, then wouldn't it be enough to just do
    GregorianCalendar gc = new GregorianCalendar();why is it necessary to declare a variable of the parent class and assign a subclass reference to that variable?

    then why does the tutorial show this?Why not? It's legal Java. It's what I would probably write, unless I knew I was going to use some methods that were in GregorianCalendar and not in Calendar.

  • Questions regarding Inheritance

    I have written my questions in the code as comments:
    Q: A) What is the difference between q and h?? Does Person q get overwritten with type PersonAddress?
    Q: B) Why does this not compile? I have tried to replace q with i and then it works but why??
    class Person
    { private String name;
        public Person(String n)
        name = n;
        public String getName()
        return name;
        public boolean sameName(Person other)
        return  getName().equals(other.getName());
    class PersonAddress extends Person
    { private String address;
        public PersonAddress(String the_name, String the_addr)
      { super(the_name);
        address = the_addr;
        public String getAddress()
        return address;
        public boolean same(PersonAddress other)
        return sameName(other) && address.equals(other.getAddress());
    class Test
      public static void main(String[] args)
        Person p = new Person("Jakob");
        // Q: A) What is the difference between q and h?? Does Person q get overwritten with type PersonAddress?
        Person q = new PersonAddress("Jakob", "Nowhere");
        PersonAddress h = new PersonAddress("Jakob", "Nowhere");
        PersonAddress i = new PersonAddress("Jakob", "Nowhere");
        System.out.println(q.sameName(p));
        System.out.println(h.sameName(p));
        //Q: B) Why does this not compile? I have tried to replace q with i and then it works but why??
        System.out.println(q.same(h));
    }

    q = child
    Person = "Something blue"
    new PersonAddress = blueberry
    But q becomes new PersonAddress (blueberry)
    Hope I am not making to much a fool out of myself :-)Hi,
    Sorry that I confused you. I thought of a real life situation.
    Variables references things, and when you declare them you have to say what they should be able to reference (that's why I said that they could point at things, but they will not become things). The actual thing that they reference (point at) will not be changed or altered in any way just because you also tells some one else to reference the same thing but using another name, or declaration type.
    E.g.
    You might point at a blueberry even though you only can point at blue things.
    Another person who is only capable of pointing at berrys might point at the exact same blueberry. But this doesn't change that fact that a blueberry is a blueberry, and it will continue to be a blueberry independent of if you point at it or not.
    /Kaj
    (Now I might have confused you even more?)

  • Question regd Inheritance Concept in 00 design

    In Inheritance,when a subclass extends a Superclass,
    the subclass is a specialized version of the superclass.Right?
    class B extends A{
    So,B is a specialized version of A.
    Supposing that class B also implements an Interface:
    class B extends A implements iFace{
    So now:
    Is B a specialized version of class A or a specialized version of an interface?
    Please can anyone answer?

    Both. You can treat it as class B, class A or
    interface iFace.
    This is how you get multiple interface inheritancein
    Java.Agree on the implmentation, disagree on the theory.
    B is a specialized version of A, but the interface is
    more a facet of B.No. In "class B extends A implements C" B is-a C just as it is-a A.
    For instance, a suburu imprezza is a specialized form
    of a car - but when my wife's brother add a load of
    rubbish to it, these are interfaces that it is
    implementing. It might be implementing the
    'SillyExpensiveAlloyWheels' interfaceThat's a poor design. You wouldn't have a care implement an interface for it's accessories as it doesn't make sense to say a particular type of care is-a SillyExpensiveAlloyWheels (ignoring the singular/plural mismatch).
    Look at the Collections framework.
    LinkedList is a list. It is a Collection. It is a Serializable. It is a Cloneable. It is an Object.
    An interface that a class implements is not just a "facet" of that class.

  • Quick question about inheritance and exceptions

    If I have two classes like this:
    public class ClassA {
        public void myMethod() throws NumberFormatException {
          throw new NumberFormatException();
    public class ClassB extends ClassA {
        public void myMethod() {
    }Does myMethod() in classA override myMethod in classB?
    And why?
    Thank you,
    V

    I just want to add that since NumberFormatException is
    a descendant of RuntimeException, you are not required
    to declare that the method throws this exception. Some
    people think it is a good idea to declare it anyway
    for clarity. Personally, I don't think so.I agree.
    I think Sun recommends that you don't declare unchecked exceptions in the method declaration, but do document them in the javadoc comments.

  • A simple question abt Inheritance

    hello friends
    whats wrong with this code?
    class R{
          int x = 0;
          void display(){
                System.out.println("Display from R");}
    class Q extends R{
          float a, b;
          void display()
                System.out.println("Display from Q") ;}
    class finalEx1{
        public static void main (String asd[])    {
               R r = new R();
               r.display();
               Q q = new Q();
               q.display();
               super.display();
    }}bye

    hello friends
    whats wrong with this code?
    class R{
    int x = 0;
    void display(){
    System.out.println("Display from R");}
    class Q extends R{
    float a, b;
    void display()
    System.out.println("Display from Q") ;}
    class finalEx1{
    public static void main (String asd[])    {
    R r = new R();
    r.display();
    Q q = new Q();
    q.display();
    super.display();
    }}byeI think the problem is the line "super.display();". Your class finalEx1 does not extend R or Q. It extends Object. And Object does not have a method called display. Maybe tell us what you wanted that line of code to do, and we can tell you what the code should say.
    Also, by convention, a class should start with a capital, as in FinalEx1, not finalEx1.
    - Adam

  • OOP question involving inheritance

    Hello,
    I am trying to build an application using OOP, which I am new to, and have a problem. The attached zip file has some dummy code which when run will show the problem, in the stop case. I seem to be able to add classes to a parent, but the parent data is being overwritten apparently.
    Tay
    Solved!
    Go to Solution.
    Attachments:
    Dummy App.zip ‏141 KB

    There is one issue in your code.
    Every time you change a state, you take an NEW object. The new object don't know anything about what you have done in a state before.
    Therefor it seems that the parents data is overwritten, but that is not the case. You are overwriting the hole objact with a new fresh object, which parent dot have any data.
    It is each object that remembers its own data, also what its parent can have, no matter if different classes have the same parent.
    The parent - child relation is not a way to share data between objects. it is a way to define a class with commen methods for different classes.

  • A question about Inheritance

    Hi,
    I have created a class which implements java.sql.Connection.
    class newConnnection implements Connection{
        close(){
            freeConnection();
    }In my main class I am assigning newConnection object to a Connection object because I want to use the Connection's close method to actually close the connection.
    main{
        newConnection newConn = newConnection();
        Connection conn = (Connection)newConn
        conn.close();
    }But it doesn't use the Connection class method. It uses the newConnection class method. Is there any way I can make use of the Connection method close?
    Thanks.

    But here's what I'm actually doing:
    I think that there is still a way I can use the Connection object.
    // Close all connections in the connection list
         public void closeConnections(Vector connList) throws SQLException{
              Enumeration connections = connList.elements();
              while(connections != null && connections.hasMoreElements()){
                   Connection connection = (Connection)connections.nextElement();
                   if(!connection.isClosed())
                        connection.close();
    connections contains objects but they are the newConnection objects. So when they get assigned to connection, connection actually turns into newConnection and ends up calling the newConnection.close() method

  • Inheritance - instance variable initialization

    Hi all.
    I have a question regarding inherited instance variables.
    class Animal {
       int weight;
       int age = 10;
    class Dog extends Animal {
       String name;
    class Test {
       public static void main(String[] args) {
          new Dog();
    }This is just an arbitrary code example.
    When new Dog() is invoked, I understand that it's instance variable "name" is give the default
    type value of null before Dog's default constructor's call to super() is invoked.But Im a little perplexed about
    Animals instance variables. I assume that like Dog, Animals instance variables are given their default type values
    of 0 & 0 respectively, before Animals invocation of super(); What im unclear about is that at the point that weight and age are given their default type values, are Dog's inherited weight and age variables set to 0 aswell at that exact moment? Or are Dog's inherited weight and age variables only assigned their values after Animals constructor fully completes because initialization values are only assigned to a classes instance variables after it's call to super().
    Many thanks & best regards.

    Boeing-737 wrote:
    calvino_ind wrote:
    Boeing-737 wrote:
    newark wrote:
    why not throw in some print statements and find out?Super() or this() have to be the very first statement in a constructor..
    Also you cannot access any instance variables until after super or this.
    :-S
    Kind regardsbut if you add the "print" statement in animal constructor, you can easily see what happened to the attributes of Dog ; that s the trick to print "before" super()You can never add a print before super(). It's a rule of thumb, super() and this() must always be the first statements
    in a constructor, whether added implicitly by the compiler or not. In this case there are 2 default constructors (inserted by the compiler), each with a super() invocation. Even if i added them myself and tried to print before super(), the compiler would complain.
    Thanks for the help & regards.you didn't understand what i meant ; take a look at that:
    class Animal {
       int weight;
       int age = 10;
       public Animal() {
           Dog thisAsADog = (Dog) this;
          System.out.println(thisAsADog.name);
          System.out.println(thisAsADog.x);
    class Dog extends Animal {
       String name;
       int x = 10;
    public class Test {
       public static void main(String[] args) {
          new Dog();
    }this way you will know what really does happen

Maybe you are looking for

  • Trouble with colors not appearing correctly.

    This has been an ongoing problem. I have created links within my pages and assigned the links different colors to help the user determine which link it is. On some pages the colors appear correct and the next page the color links appear as black. Som

  • Firewire Output for Video Preview Intermittent

    I'm experiencing a frustrating problem with After Effects these days. We're producing some video to be projected, so to see what the final output will really look like, I'm doing video previews using FireWire so output goes directly to the projector.

  • Critical Services Not Starting Automatically & Access to Server occasionally dropping out

    For the last few months we have been trying to resolve an issue where access to files on the server (SBS2011 - running domain services, exchange, etc) get so slow or just unresponsive. Logging onto the server is also not possible till it starts respo

  • LSMW for PR Creation

    Hi all, I've created LSMW for PR using the following parameters: Step 1 : Direct input: Object  0080 Method 0000 Program Name RM06BBI0 Step 3 : Maintain Source Fields i define source fields as following: HEADER_STRUCTURE   -> ITEM_STRUCTURE header_st

  • Download link for 4.2.1?

    My internet at home is too slow for the update. Can anyone direct me to a direct download site of the final released version of 4.2.1 that I can download at work and then slip into iTunes? Thanks