Redefination of Method in Inherited Class

dear Gurrus i am facing an issu.
I have defined and implimented 2 classes A and B,
B is inherited by A and B has also redefined an inherited method of A. at runtime i have created an  object of B and called a redifined method. and its working properly, but i have a requirment that i want to get result of the method orginally defined by class A and also at the same time i also want to see the result of redefined method by B.
can i access the method of A class althoug i have redefiend the same method in B class using the object of B?
Edited by: Shadab Ali on Jun 4, 2009 8:55 PM

I spent a while looking into this after reading your question, and came to much the same conclusion you had. Here's the best I could come up with, but it suffers from all the flaws you mentioned:
     public static Type report(Method method, Class contextClass) {
          Type grt = method.getGenericReturnType();
          Class dc = method.getDeclaringClass();
          TypeVariable[] tva = dc.getTypeParameters();
          Class directDescendent = contextClass;
          while( !directDescendent.getSuperclass().equals(dc)) {
               directDescendent = directDescendent.getSuperclass();
          Type t = directDescendent.getGenericSuperclass();
          if( t instanceof ParameterizedType ) {               
               ParameterizedType pt = (ParameterizedType)t;
               int index = 0;
               for( Type ta : pt.getActualTypeArguments() ) {
                    if( tva[index++].equals(grt) ) return ta;
          return null;
     }Might be worth asking this again in the Generics forum.

Similar Messages

  • Redefining a method

    Is it possible to redefine a method of a class within an already instantiated instance of that class? For example if I have ...
    class Dog{
      public boolean isBigDog(int width, int height){
        return true;  // always says its a big dog
      public void sitOnCouch(){
         if(isBigDog(with,height){
           System.out.println("Dog can sit on the couch");
         }else{
           System.out.println("Dog CAN'T sit on the couch");
    public static void main(String[] args){
      Dog dog = new Dog();
      dog.sitOnCouch();  // prints out "Dog can sit on the couch"
      //now if I didn't want that same dog, not a new one, to sit on the couch how can I redefine isBigDog()
      //for that instance of dog?
    }What I am really trying to do is to redfine the isCellEditable(int row, int col) in the DefaultTableModel class on an already instantiated DefaultTableModel. User click's a check box to allow cells to be editable or not to be editable.

    AwhHawh.... GOT IT! In case anyone cares for this
    bit of code it will "change cell editable on the fly".Not bad at all. However it has the side effect of creating a whole new model and throwing away
    the old one. Let me suggest this instead, as per my previous post recommending a subclass:public class MyDefaultTableModel extends DefaultTableModel {
      // local variable to store "editable" status
      private boolean isEditable = true;
      public MyDefaultTableModel(Object[][] data, Object[] columnNames) {
        super(data, columnNames);
      public DefaultTableModel(Object[] columnNames, int rowCount) {
        super(columnNames, rowCount);
      // implement any other constructors you need like the above
      // method to change "editable" status
      public void setAllowEditing(boolean allow) {
        isEditable = allow;
      // override isCellEditable to use our private variable
      public boolean isCellEditable(int row, int column) {
        return isEditable;
    }Hope this helps.
    PC²

  • Inherited methods of super class not shown in outline

    Hello, is there a possibility to display the methods and variables from the super class in the outline of the inheriting class in AiE?

    Hi Christian,
    We had discussed this, when we implemented the outline and quick outline some years, ago. Finally, we sticked to the approach that is used by other plug-ins in Eclipse (like JDT).
    There Outline View shows only the content of the current editor. This helps to keep the content of the view stable when you select an element for navigation (because you won't be able to switch the editor by selecting an element ).
    Inherited members are usually part of other editors, unless you have redefined a method in your current class. Therefore, they are not shown in Outline View (unless they are redefinitions).
    The filters like "Hide Non-Public Members of classes" can only hide elements of the current editor.
    Inherited members can be shown in the Quick Outline, because the interaction pattern is different there: If you navigate to an element the pop-up is closed. Therefore, a content change of the Quick-Outline does not hurt.
    Michael

  • How do I redefine a Method of a Final Class?

    Hi,
    Is it possible to redefine a method of a final class and if so, can someone please give me a brief example of that technique?
    Thank you very much!
    Andy

    Hi,
    Please find the example.
    Program Description :      Interface I1 contains two methods : M1 and M2.
    I1 is included and incorporated in class : C1 with M2 as a final method. Both the methods are implemented in class C1.
    Class C2 is a subclass of class C1. It redefines method : I1M1 and re-implements it, but it does not do that for I1M2 as that is declared as final method.
    In the START-OF-SELECTION block, object OREF1 is created from class C1 and OREF2 from class C2 and both the methods M1 and M2 are called using both the objects.
    Example:
    report ytest .
    interface i1 .
      methods : m1 ,
                m2 .
    endinterface.
    class c1 definition.
      public section.
       interfaces : I1 final methods m2 .
    endclass.
    class c1 implementation.
      method i1~m1.
       write:/5 'I am m1 in c1'.
      endmethod.
      method i1~m2.
       write:/5 'I am m2 in c1'.
      endmethod.
    endclass.
    class c2 definition inheriting from c1.
      public section.
       methods : i1~m1 redefinition .
    endclass.
    class c2 implementation.
      method : i1~m1.
       write:/5 'I am m1 in c2'.
      endmethod.
    endclass.
    start-of-selection.
      data : oref1 type ref to c1,
             oref2 type ref to c2 .
       create object : oref1 , oref2.
       call method  : oref1->i1~m1 , u201C Output : I am m1 in c1
                      oref2->i1~m1 , u201C Output : I am m1 in c2
                      oref1->i1~m2 , u201C Output : I am m2 in c1
                      oref2->i1~m2 . u201C Output : I am m2 in c1
    Output :      I am m1 in c1 
    I am m1 in c2 
    I am m2 in c1 
    I am m2 in c1 
    Thanks,
    Anitha

  • ABAP Objects : calling one method from another class

    Hi,
    Can you please tell me how to call method from one class or interfce to another class.The scenario is
    I have one class CL_WORKFLOW_TASK, this class have interface IF_WORKFLOW_TASK & this interface have method IF_WORKFLOW_TASK~CLOSE. Now my requirement is ,
    There is another class CL_WORKFLOW_CHAIN ,this class have interface IF_WORKFLOW_CHAIN & this interface have method IF_WORKFLOW_CHAINCLOSE_ALL_PREDECESSORS. Now i have to write my code in this method but i have to use IF_WORKFLOW_TASKCLOSE method for closing the task.
    Can you please give me the code for the above .
    Please waiting for reply.

    Hi,
    You can use the concept of INHERITANCE  in this scenario.By using this concept, you can call all the public and protected  methods of class CL_WORKFLOW_TASK  in the required calss CL_WORKFLOW_CHAIN as per your requirement.
    Go through the  Introdctory(INHERITANCE) programming from this SAPHELP link.
    http://help.sap.com/saphelp_nw70/helpdata/en/1d/df5f57127111d3b9390000e8353423/content.htm
    I hope, it will help in you inresolving your problem.
    by
    Prasad GVK.

  • Redefine static method?

    It seems that I cannot redefine a static method in a subclass in ABAP OO, right?
    Is there a reason for that? Is this like this in other languages as well?

    That's true. You cannot redefine static methods in ABAP OO.
    I can add that a class that defines a public or protected static attribute shares this
    attribute with all its subclasses.
    Overriding static methods is possible for example in Java.
    This simple piece of code illustrates this:
    public class Super {
        public static String getNum(){
            return "I'm super";
         public static void main(String[] args) {
             System.out.println("Super: " + Super.getNum());
             System.out.println("Sub: " + Sub.getNum());
    public class Sub extends Super{
        public static String getNum(){
            return "I'm not";
    The output is:
    Super: I'm super
    Sub: I'm not
    When overriding methods in Java you must remember that an instance method cannot override a static method, and a static method cannot hide an instance method.
    In C# a static member can't be marked as 'override', 'virtual' or 'abstract'. But it it is possible to hide a base class static method in a sub-class by using the keyword 'new':
    public class Super
      public static void myMethod()
    public class Sub: Super
      public new static void myMethod()

  • Referencing a method in one class from a constructor in another?

    Hi,
    I'm not sure whether this is a simple question or not, but instead of rewriting the method in another class, is there a way that I can reference that method, eg:
    public int getTitleCode() {
            return titleCode;  }within the constructor of another class. I don't want to use inheritance with this because it would change all my existing contructors.
    Any ideas how to do this, or is it just simpler to add the method to both classes?
    Many thanks!

    Hi,
    I'm trying to use a method, defined in Class A, within one of the constructors in Class B. Class B object represents a copy of the output of Class A, with the addition of a few extra methods.
    Therefore to represent the details correctly in the saved text file for class B, I need to call a method from class A to save the text file for class B correctly.
    Class B saves a file with a reference number unique to that class, plus a reference number that is also saved in the text file for class A.
    I can achieve the correct result for the above by having the same method in both classes, but I just wondered whether instead of this I could in fact call the method from class A in the constructor for class B. With the following code,
        referenceNumber = refNum;
            titleReferenceNumber = titleRefNum;
            titleRefNum = titles.getTitleCode();
        }I just get a 'nullpointerexception' when I try to run this in the main class.
    Any help or advice appreciated!

  • How to Access Protected Method of a Class

    Hi,
         I need to access a Protected method (ADOPT_LAYOUT) of class CL_REIS_VIEW_DEFAULT.
    If i try to call that method by using class Instance it is giving error as no access to protected class. Is there any other way to access it..

    Hi,
        You can create a sub-class of this class CL_REIS_VIEW_DEFAULT, add a new method which is in public section and call the method ADOPT_LAYOUT of the super-class in the new method. Now you can create an instance of the sub-class and call the new sub-class method.
    REPORT  ZCD_TEST.
    class sub_class definition inheriting from CL_REIS_VIEW_DEFAULT.
    public section.
      methods: meth1 changing cs_layout type LVC_S_LAYO.
    endclass.
    class sub_class implementation.
    method meth1.
      call method ADOPT_LAYOUT changing CS_LAYOUT = cs_layout.
    endmethod.
    endclass.
    data: cref type ref to sub_class.
    data: v_layout type LVC_S_LAYO.
    start-of-selection.
    create object cref.
    call method cref->meth1 changing cs_layout = v_layout.

  • Use CAST to check if an instance belongs to inherited classes.

    Dear all.
    I have got a method called GET_LINKS which is supposed to give back all references in an internal table which are of a given class or belong to classes being inherited.
    ( I do not have both - access to the internet and our R3 at once that is why I only provide pseudo code)
    Example:
    think of follwing structure:
      cl_object
         cl_class1
            cl_class11
         cl_class2
            cl_class21
            cl_class22
    so if check against cl_objets the method should give back all references .... if cl_class1 only those who belongs to cl_class1 or class11...you got the idea.
    so My method looks somewhat like following.
    method get_links.
    * changing  ch_instance type ref to object.
    * returnning re_links (table of instances)
    loop at ait_links into lwa_links.
      catch system-exception - move_cast_error
       ch_instance ?= lwa_links-instance.
      endcatch.
      if sy-subrc is initial.
        insert lwa_links into table re_links.  
      endif.
    endloop.
    endmethod.
    coding works fine so far - the only thing I do not like is that I have to provide a changing parameter for the cast. I would prefer a local copy of an importing parameter for the checks.
    But as soon as I use a very generic type declaration - like ref to object - no casting error will take place and I am not able to differentiate the groups down the inheritance.
    I tried to create a dynamic reference variable but failed. I guess I would need to create a type dynamically but this is not possible before 6.4 (and I am on 4.6c)
    Any suggestion for that?
    Thank you very much.
    Christian

    Hi, list my suggestion as following:
    'ch_instance type ref to object'
    As it is defined as an object type,
    'ch_instance ?= lwa_links-instance.' won't catch any error, because OBJECT is the root type of any object type, if you only need to compare them and differentiate the class and inherited class from others, you can do like this:
      catch system-exception - move_cast_error
       lwa_links-instance ?= ch_instance.
      endcatch.
    By the way, I don't know what's the definition of lwa_links-instance is. I wrote some sample code for you scenario, as list it as following:
    * I create two inherited class
    CLASS C1 DEFINITION INHERITING FROM CL_ABAP_TYPEDESCR.
      PUBLIC SECTION.
        DATA: C1  TYPE  C.
    ENDCLASS.
    CLASS C2 DEFINITION INHERITING FROM CL_GUI_CONTROL.
      PUBLIC SECTION.
        DATA: C2  TYPE  C.
        METHODS CONSTRUCTOR.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
      METHOD CONSTRUCTOR.
        CALL METHOD SUPER->CONSTRUCTOR EXPORTING NAME = 'aaa'.
      ENDMETHOD.
    ENDCLASS.
    * assume that you have a class, using CL_ABAP_CLASSDESCR
    * we can get the name of it
    DATA:
    descr_ref TYPE ref to CL_ABAP_CLASSDESCR.
      descr_ref ?= cl_abap_typedescr=>DESCRIBE_BY_OBJECT_REF( CLass ).
    * then we can transfer the class name into the module get_links
    module XXXX.
      DATA: A  TYPE  REF TO C1,
            B  TYPE  REF TO C2,
            R  TYPE REF TO OBJECT.
      CREATE OBJECT A.
      CREATE OBJECT R TYPE ('C1').
    * here it goes well
    * as the A type is C1, and R is create as C1 too
      CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
        A ?= R.
      ENDCATCH.
      CREATE OBJECT R TYPE ('C2').
    * here it can catch the error
    * as the A type is C1, and R is create as C2, C1 & C2 has
    * no relation like inherit
      CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
        A ?= R.
      ENDCATCH.
    * XXXX is the class name which transfered into module
      CREATE OBJECT R TYPE ('XXXX'). 
    * then try to create the class according to class name
    * which is you want
      CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
        A ?= R.
      ENDCATCH.
    Hope my reply can help you solve the problem
    By the way, the code cost me some time, so don't forget the reward points
    thanks a lot

  • Redefine Interface Method

    Hi, I am using a BI Interface "IF_RSCNV_EXIT" and I am adding code to the "Exit" Method. 
    Do I need to redefine this method?  The reason I ask is because the redefine icon is greyed out even though I am in edit mode.
    Thanks!

    Hello Kenneth
    Interface methods are always empty. You can implement them only once within a hierarchy of classes using this interface. Thus, you cannot redefine it.
    Regards
      Uwe

  • Redefine a method

    Hi All,
    I am working on CRM 5.0 version. Can some one tell me the procedure as to how to redefine a method. I would want to redefine a method to add my custom functionality. I was searching for "Redefine" button but i dont get to see it. Can some one help?
    Thanks.

    Hi There,
    The redefine button is in the class builder under the methods tab and second from the right, it is a circle thing with a tool stuck to it. If there is no such button, you are likely looking at an interface, which has no implementation to redefine. If the button is greyed, you need to be in change mode.
    I'm assuming this is for the IC Webclient am I right? If so, be sure you are using the proper technique for enhancing the view - as outlined in the CRM 5.0 IC Web Client Consultant's Cookbook. It is not good practice to redefine the method of an SAP class if you can avoid it. Best is to derive a class from the SAP class, and then redefine the method in the derived class.
    Hope this helps.
    Sincerely,
    Glenn
    Glenn Abel
    Covington Creative
    www.covingtoncreative.com

  • Reflecting methods of parent class

    I have a class named ParentClass with a public method named getName that takes a String as a paramenter and returns a String.
    If I extend ParentClass, how can I use reflection to access the getName method of the parent (super) class? I get a NoSuchMethodException if I try to get the subclass to reflect any methods it inherits from its parent.

    Also ,I modified the above example to print the method return value . It work fine.
    import java.lang.reflect.Method;
    public class TestReflection {
         public static void main(String[] args) throws Exception{
              SubClass cls = new SubClass();
              Method m = cls.getClass().getMethod("getName", new Class[] {String.class});
              System.out.println(m.invoke(cls,new Object[] {new String("testing name")}));
    class ParentClass {
         public String getName(String s) {
         return s;
    class SubClass extends ParentClass {}

  • Inheritance class not working

    Alright, so I'm supposed to write an inheritance class called MusicStore, which is inherited from the Store ( already written), and then the MusicStore method tests out the MusicStore. The MusicStore has the additional attributes of the number of titles it offers and the its address...The store already offers the name of the store where the titles are located...I believe I'm writing it the MusicStore correctly, but I get this really odd error when I compile...I am not quite sure how it happens????? Helllpppp!!! I would appreciate it
    I will post the error and the error is located a bit lower in the MusicStore that I posted-
    "File: E:\comp 150\H10\MusicStore.java [line: 13]
    Error: E:\comp 150\H10\MusicStore.java:13: cannot find symbol
    symbol : constructor Store()
    location: class Store"
    Here is the Store:
    /* Store Class
       Anderson, Franceschi
    public class Store
      public final double SALES_TAX_RATE = 0.06;
      private String name;
      public Store( String newName )
        setName( newName );
      public String getName( )
        return this.name;
      public void setName( String newName )
        this.name = newName;
      public String toString( )
        return( "name: " + this.name );
      public boolean equals( Store otherStore )
        return ( this.name.equalsIgnoreCase( otherStore.name ) );
    }Here is the MusicStore:
    /* MusicStore class
    Smith, Tahnee
    public class MusicStore extends Store
      public final int DEFAULT_NUMBER = 0;
      private int numberOfTitles;
      public final String DEFAULT_ADDRESS = " ";
      private String address;
      public MusicStore()
      {                                         // LINE 13 : Here is where the error is...I don't understand what is going on here.
        address = DEFAULT_ADDRESS;
        numberOfTitles = DEFAULT_NUMBER;
      public MusicStore(String startNameStore, int startNumber, String startAddress)
        super( startNameStore );
        setNumberOfTitles( startNumber );
        setAddress( startAddress);
      public void setAddress( String newAddress)
        address = newAddress;
      public void setNumberOfTitles(int newNumber)
        if ( numberOfTitles > 0 )
          numberOfTitles = newNumber;
        else
          System.out.println(" Number of titles cannot be negative");
      public String toString()
        return super.toString()
          + " The number of titles are " + numberOfTitles
          + " The address is " + address;
    }Here is the MusicStoreClient:
    /* MusicStoreClient class
       Anderson, Franceschi
    public class MusicStoreClient
      public static void main( String [] args )
        MusicStore ms1 = new MusicStore( "Records, Inc.", 1000, "123 Elm Street" );
        MusicStore ms2 = new MusicStore( "All Records Unlimited", 1200, "999 Green Street" );
        System.out.println( ms1 );
        System.out.println( ms2 );
        ms2.setNumberOfTitles( 1000 );
        ms2.setAddress( "123 Elm Street" );
        if ( ms1.equals( ms2 ) )
          System.out.println( "ms1 and ms2 are equal" );
        else
          System.out.println( "ms1 and ms2 are not equal" );
        ms2.setName( "Records, Inc." );
        if ( ms1.equals( ms2 ) )
          System.out.println( "ms1 and ms2 are now equal" );
        else
          System.out.println( "ms1 and ms2 are still not equal" );
    }Edited by: guitarlady3000 on Nov 5, 2008 4:22 PM
    Edited by: guitarlady3000 on Nov 5, 2008 4:37 PM

    You don't explicitly call the super(...) constructor in your parameterless MusicStore constructor code and so Java will automatically and behind the scenes place a call to super() there. Problem is, Store doesn't have a parameterless constructor. Solution: either give Store a parameterless constructor or explicitly call super with a proper parameter.

  • Get_Children Method in CL_BSP_WD_TREE_NODE_PROXY Class - Tree View

    Hi
    When I have created the Zclass by taking the super class as CL_BSP_WD_TREE_NODE_PROXY. Afterthat I am going to redefine the method GET_CHILDREN in CL_BSP_WD_TREE_NODE_PROXY class, its not going to allow me to enter the code in this method.
    Message its showing - IF_BSP_WD_TREE_NODE~GET_CHILDREN is abstract and has not been redefined.
    Kindly let know how to resolve this.
    Regards
    Deepanker Mahajan

    Hi,
    I have to say this is not a CRM specific question, this should be more ABAP programming related. But anyway, let me have a try.
    I've performed the following steps successfully:
    1.se24, enter Class name ZHY_BSP_WD_TREE_NODE_PROXY, click Create button,
    2.select Class, click green tick,
    3.click on the "Create inheritce" button beside my class name, this brings Superclass field, and enter CL_BSP_WD_TREE_NODE_PROXY, leave everything as defaulted: Usual ABAP Class, and Final, click save button,
    4.On Methods tab, locate IF_BSP_WD_TREE_NODE~GET_CHILDREN, and put cursor on it, and click button "Redefine"
    5.Now it brings me to the coding change screen, and I am able to add codings freely, and activate and save is possible and succeeded.
    Any step that I made a difference compared to yours?
    Hongyan

  • Final&private methods in inheritance

    Hi all,
    We know that in inheritance private methods are not inherited by sub classes. In addition to this it's also known that final methods are inherited but cannot be changed. Then what is the use of using private methods when there is final methods which cannot be changed, that is why to hide our methods, are they(private methods) something that must be encapsulated as they behave like supporting methods?

    Yes, you hide methods by making them private in order to hide implementation details.

Maybe you are looking for

  • How do I explode an object?

    Hi, I would like to make an object explode. I tried using the explode timeline effect in Flash CS3, but it doesn't look very realistic. I could overlay some footage of a fireball in front of the item, but I'm really looking to create the perception t

  • Sharing internet from macbook pr

    I have a sprint wireless card for my internet connected to the express slot in my MBP. Previously, I turned on internet sharing in the system preferences and shared from my express card to ethernet. The ethernet would connect to the wan port on the A

  • Need help on abap-hr smartform and scripts

    hi experts im new to abap-hr i want some standard hr scripts and smartforms where i wll get those ? and in real time we mostly worked on which forms in RE OM PA and PAYROLL modules?

  • Xserver-1.5.3 doesn't reset resolution after ending a full screen game

    xserver-1.5.3 doesn't reset display resolution after ending a full screen game. Is this a issue of the new xserver or the ati driver (i switched from catalyst to xf86-video-ati)? And how can i solve it? so long ukognos Last edited by ukognos (2008-11

  • How to load data to dimensions and fact table is it simialr to sql server

    How to load data to dimensions and fact table in a data ware house environment, is it simialr to sql server, oracle? Never migrated or loaded data to datawarehouse server. I have an interview and am really confused if they ask anything related to the