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²

Similar Messages

  • Redefine Static Methods in ABAP OO

    Hello,
    I want to redefine an public static method and returns always an error.
    Okay, I already solved the problem with an workaround, but I still don't understand, why it is not possible to redefine static methods in ABAP OO.
    If someone can give me an plausible reason, so I don't have do die stupid. G
    Thanks for help!
    Matthias

    It is built into the language that way.  HEre is a link that may or may not give you an answer.
    redefine static method?
    Regards,
    Rich Heilman

  • 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()

  • 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

  • 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

  • Message thrown while trying to redefine the method GOSAddObjects in SWO1

    Hi,
    I am trying to create a Business Object in SWO1 for GOS. I want to redefine the method GOSAddObjects but when I am trying to do this it shows the Message no. OL645 (Composite definition not allowed for local elements). Please help to solve this issue.
    Thanks and Regards,
    Rahul M.B.

    To edit this method, if F6 is not working,,we can:
    -> Select/ point cursor on 'GOSAddObjects'
    -> On toolbar, theres a button 'Program' -> Click on it and you can edit now.
    Regards,
    KS

  • Redefining Query method for BP search

    Hi All,
    I added sales office and sales group field in BP search page (COMM_BUPA_SEARCH) ,
    I created child class for CL_BSP_BP_ACCMOD i.e. ZCL_BSP_BP_ACCMOD and tried to redefined Query method.
    But in IF_CRM_BSP_MODEL_ACCESS_IL~QUERY there are some private attribute of Super class, because of that I am facing the error.
    Please advise me in
    1) What should I do to add sales office and sales group in query  criteria .
    2)To add sales office and sales group fields on search screen I created new field group and add that in BUP_BUS1006_SEARCH_ALL_FIELDS (Group type attribute is set to Screen Group) But on page the title of screen group is still "Search By Role", insted of "Search by sales Info" (This is description of newly added field grp)
    Swanand

    1) If am not mistaken, there is a variable in the standard SAP program called lv_where_clause for the search query.But this would be a modification. try looking into this program SAPLCRM_BUPA_BSP_SEARCH_ACC. try putting a break point and see if this is where you wanted to add the field in your query.
    Thanks,
    Shailaja

  • Getting while Redefining Save_objects Method ....

    I have inherited CL_CRM_GENIL_ABSTR_COMPONENT2 in my class and while redefinig
    IF_GENIL_APPL_INTLAY~SAVE_OBJECTS method ... I am getting error message like this
    You cannot redefine the final method IF_GENIL_APPL_INTLAY~SAVE_OBJECTS.
    Is there any method to redefine method

    HI Saurabh,
    Seems like there is an issue with your java heap memory... could you please ask your admin to check and increase your heap memory in exchange profile .
    This solves your issue.
    Also pls refer to Note 723909 - Java VM settings for J2EE 6.40/7.0
    Cheers!!!
    Naveen.

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

  • Deletion of Redefined Method

    Hello,
    in se80 I work on class which has a super class.
    I redefined a method of this class.
    Later on  I deleted the redefined method.
    When activiating, the compiler throws an error that the method is already implemented.
    When navigating to the error it shows the method stub, which is supposed to be deleted. In addition, the method  is not shown in the tree view. When navigating to the method definition it shows the definition of the super class.
    Can you tell me how I get rid of this method.
    Best regards
    Michael

    Hi ,
    thank you for your answer, but I think it does not solve the problem.
    The situation is.
    class child has super class parent.
    In class child I redefined method foo.
    Then I delete the redefined  method foo in class child.
    Result: The class is deleted in the class definition.
    The compiler throws an error "Class already" defined and shows the implementation of child->foo.
    A new definition as u suggested is not possible, se80 states, that method is already defined. Only a new redefiniton of the method is possible.
    What I hav done now is.
    1. delete the defintion of the redefined method
    2. Comment or delete the implementation of method
    Result: The class can be activated.
    But  I am not sure that this this the correct way, but it temporarily solves my problem.
    Best regards
    Michael

  • Hook methods in ABAP Objects

    Hello,
    i discovered that method calling in the class-inheritance of ABAP Objects doesn't work similar to other OO languages.
    Example:
    1 Superclass named "Z_CLASS"
    1 Subclass of "Z_CLASS" named "Z_SUB"
    Z_CLASS defines a method "initialize" and has a constructor which calls "initialize".
    Z_SUB redefines the method "initialize" assigning some values to instance-attributes.
    If i instantiate a new "Z_SUB"-object then the contructor of "Z_CLASS" is called which calls ITS OWN "initialize" not the one of the subclass. For comparison: Java would call the initialize of the subclass.
    I have to implement a constructor in every subclass of "Z_CLASS" which calls the super constructor and the own "initialize" after that to solve this problem. This isn't the proper OO way!
    Did i miss something or am i right?
    Thanks in advance,
    Stefan

    Check out this, it might be helpfull...
          INTERFACE I_COUNTER
    INTERFACE i_counter.
      METHODS: initialize.
    ENDINTERFACE.
          CLASS C_COUNTER1 DEFINITION
    CLASS c_counter1 DEFINITION.
      PUBLIC SECTION.
        INTERFACES i_counter.
        METHODS: constructor.
        DATA count TYPE i.
    ENDCLASS.
          CLASS C_COUNTER1 IMPLEMENTATION
    CLASS c_counter1 IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD me->i_counter~initialize.
      ENDMETHOD.
      METHOD i_counter~initialize.
        count = count + 10.
        write:/ 'count from super', count.
      ENDMETHOD.
    ENDCLASS.
          CLASS C_COUNTER2 DEFINITION
    CLASS c_counter2 DEFINITION INHERITING FROM c_counter1.
      PUBLIC SECTION.
        METHODS: constructor,
                 initialize.
        DATA count1 TYPE i.
    ENDCLASS.
          CLASS C_COUNTER2 IMPLEMENTATION
    CLASS c_counter2 IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD super->constructor.
        CALL METHOD me->initialize.
      ENDMETHOD.
      METHOD initialize.
        count = ( count / 10 ).
        write:/ 'count from sub', count.
      ENDMETHOD.
    ENDCLASS.
    DATA: count TYPE REF TO c_counter2.
    START-OF-SELECTION.
    CREATE OBJECT count TYPE c_counter2.

  • View not copied or enhanced with wizard Error while creating Event Handler method in Z Component

    Hello Friends,
    In one Z Component (Custom Component), in one of the views, while creating event handler, it gave me error message that view not copied or enhanced with wizard.
    I am aware that in Standard Component, if we want to create the event handler method then we need to first Enhance the Component and then we need to enhance the view.
    But, in the Z Component (Custom Component), how to create event handler method in one of the views as while creating event handler method i am getting view not copied or enhanced with wizard error.

    Hi,
    Add a method in views impl class with naming convention eh_on__* with htmt and html_ex parameters.  I dont have have the system right now. Please check any existing event import export parameters.
    Check out do handle event method in the same class.
    Redefine that method.  Call that event method in this handle method. See existing code for reference.
    Attach that event to the button on click event in .htm page.
    Regards,
    Bhushan

  • How to get GUID in DO_INIT method

    Hi All,
    I have a requirement to default the CC mail id's when a follow up email is created from complaint i am trying to acheive this
    by redefining DO_INIT method and created a new method set_CCmailid where i am trying to call order_read to get the partner
    functions and their mail id's.Plz let me know how should i get the guid to pass to order_read and attend functionality.
    Thanks.

    Hi Anjum,
    You can try to read the current business transaction GUID in email view by reading global data context reference. Something like this:
    *- Data dictionary
      DATA lr_gdc            TYPE REF TO if_crm_ui_data_context.
      DATA lr_bt             TYPE REF TO cl_crm_bol_entity.
      DATA lv_guid          TYPE crmt_object_guid.
    *- Get current business transaction from global data context
      lr_gdc ?= cl_crm_ui_data_context_srv=>get_instance( ).
      CHECK lr_gdc IS BOUND.
      lr_bt ?= lr_gdc->get_entity( name = if_iccmp_global_data_cont_con=>gdc_currentbt ).
      CHECK lr_bt IS BOUND.
      lv_guid = lr_bt->get_property_as_string( 'CRM_GUID' ).
    Kind regards,
    Garcia

  • ABAP OO Abstract Methods

    Hi,
    I want to use abstract methods in ABAP. I created an abstract class as base and another 'child' class that extends that class. Now, I want to have different implementations in different child classes. The problem is that the IDE redirects me to the base class when trying to to this. There is no possibility to set the method as abstract.
    Do you know if that concept is implemented at all? Maybe I just forgot to configure something?!
    What do you propose?
    Thank you and best regards,
    Daniel

    Hi,
    If you are creating Local class using SE38, then just by writing "abstact" to the method it behaves like an abstract method.
    If you are creating global class SE24, then genrally all interface methods are "abstract" methods so that we can ihberit and can redefine the methods for example: "IF_FLUSH_NOTIFY~BEFORE_FLUSH_NOTIFY" symbol ~ shows that it is an abstract method in the interface before to that.
    So, even if it refer to its base class you can just implement them in the child classes by inheriting it.
    Hope this helps you if yes try to assign some app. points.
    Regards,
    Suman

Maybe you are looking for