How to call parent`s overriden method?

Hello all!
I do not know how to call overriden method outside
the class. Example:
class A {
     public String method() {
          return new String("A");
class B extends A {
     public String method() {
          return new String("B");
public class test {
     public static void main(String[] s) {
          A a = new A();
          B b = new B();
          // this is simple
          System.out.println(a.method()); // result: A
          System.out.println(b.method()); // result: B
          // now I need to call method from object A
          System.out.println(((A) b).method()); // res.: B
At the last line the result was "B". It just implies from
polymorphism but what I need is to call A.method()
on object of type B.
From real world. Have a class with some toString() method.
I inherited this class and made a new toString() methods that
adds some more information. Now I have a collection of various
sub-classes and I need to print their information but in
one style. I need to call the parent`s toString() method not
the children ones...
How to do it? How to create A.method() on object of type B?
In C# there is a way not to use virtual/ovveride but to
use virtual/new keywords...
Please help me. Thank you very much.

Just thought of something else you can try (if it's that important):public class A {
    public String toString () {
        return "A";
public class B extends A {
    public String toString () {
        return "B (A: " + super.toString () + ")";
}Kind regards,
  Levi

Similar Messages

  • How to call parent procedure in child type?

    i have two types,A and B.
    B inherits from A and overrides a procedure 'prints',
    then how call A's prints method in B?
    following is codes:
    create or replace type A as object (
    rowsID integer;
    member procedure printRowsID
    create or replace type body A as
    member procedure printMembers is
    begin
    dbms_output.put_line(rowsID);
    end;
    end;
    create or replace type B under A (
    roundNO number(2),
    overriding member procedure printMembers
    create or replace type B as
    overriding member procedure printMembers is
    begin
    dbms_output.put_line(roundNO);
    /*here i also want to print attribute value of 'rowsID',
    but how to call parent's procedure which is overrided? */
    end;
    end;

    A.<<method>> syntax is wrong here because method is
    not static.
    Unfortunately Oracle doesn't have the syntax like C++ -
    A::<<method>> - which allows you to call methods of
    superclasses directly.
    TREAT function also can't help you because even if
    you treat SELF as supertype Oracle will work with
    real type of object:
    SQL> create or replace type A as object (
      2  rowsID integer,
      3  member procedure printMembers
      4  ) not final
      5  /
    &nbsp
    Type created.
    &nbsp
    SQL> create or replace type body A as
      2  member procedure printMembers is
      3   begin
      4    dbms_output.put_line('Class A - ' || rowsID);
      5   end;
      6  end;
      7  /
    &nbsp
    Type body created.
    &nbsp
    SQL> create or replace type B under A (
      2  roundNO number(2),
      3  member procedure whatisit
      4  )
      5  /
    &nbsp
    Type created.
    &nbsp
    SQL> create or replace type body B as
      2 
      3  member procedure whatisit
      4  is
      5   aself a;
      6  begin
      7   select treat(self as a) into aself from dual;
      8   if aself is of (b) then
      9     dbms_output.put_line('This is B');
    10   else
    11     dbms_output.put_line('This is A');
    12   end if;
    13  end;
    14 
    15  end;
    16  /
    &nbsp
    Type body created.
    &nbsp
    SQL> declare
      2   bobj b := b(1,2);
      3  begin
      4   bobj.whatisit;
      5  end;
      6  /
    This is B
    &nbsp
    PL/SQL procedure successfully completed. One of workarounds is to use type-specific non-overrided
    static method:
    SQL> create or replace type A as object (
      2  rowsID integer,
      3  member procedure printMembers,
      4  static procedure printA(sf A)
      5  ) not final
      6  /
    &nbsp
    Type created.
    &nbsp
    SQL> create or replace type body A as
      2 
      3  member procedure printMembers is
      4   begin
      5    A.printA(self);
      6   end;
      7 
      8  static procedure printA(sf A)
      9  is
    10   begin
    11    dbms_output.put_line('Class A - ' || sf.rowsID);
    12   end;
    13 
    14  end;
    15  /
    &nbsp
    Type body created.
    &nbsp
    SQL> create or replace type B under A (
      2  roundNO number(2),
      3  overriding member procedure printMembers
      4  )
      5  /
    &nbsp
    Type created.
    &nbsp
    SQL> create or replace type body B as
      2 
      3  overriding member procedure printMembers
      4  is
      5   begin
      6    dbms_output.put_line('Class B - ' || roundNo);
      7    A.printA(self);
      8   end;
      9  end;
    10  /
    &nbsp
    Type body created.
    &nbsp
    SQL> declare
      2   b1 b := b(1,2);
      3  begin
      4   b1.printMembers;
      5  end;
      6  /
    Class B - 2
    Class A - 1
    &nbsp
    PL/SQL procedure successfully completed.Rgds.

  • How to call a custom controller method from view

    Hi,
    I ve created a simple web service and consumed it in a model. Mapped the input & output parameters to custom controller context which in turn mapped to component controller's context which in turn to view's contexts.
    How to call a custom controller method from view?
    Please explain the syntax.
    Regards,
    Manoj.

    Hi Patralekha,
    Give some idea for the below scenario:
    I ve created a simple web service and consumed it in a model. What I did was
    1) for the input parameters, mapped the node from view->custom controller->model
    2)for the output parameter, mapping from model->custom controller->view.
    It works fine.
    But I don't want to access model nodes directly, rather I want to set the input param in somewhere else (like custom controller) before calling the appropriate method, same for the response also.
    Share me your thoughts.
    Regards,
    Manoj.

  • How to call a standard BOR method in a program.

    Hi All,
    How to call a standard BOR method in a program. For example I have to call BOR method ISUSMORDER.Release in my program but don't know how to call.
    Also, plz tell me how to capture the Exceptions in case of BOR method.
    Plz help me out in this.
    Thanks,
    Mithilesh

    Would be easier (however not always possible), to determine the functionality of this method and call that in your program. I mean, normally this method calls a BAPI, or function module (or a transaction). Have a look at the coding inside of the method, and try and use this.

  • How to call the screen in methods could u please explain

    hi,
    how to call the screen in methods could u please explain clearly with example

    HI ,
    CALL SCREEN - Call a screen
    Basic form
    CALL SCREEN scr.
    Addition:
    ... STARTING AT x1 y1 ... ENDING AT x2 y2
    Effect
    Calls the screen scr; scr is the number of a screen of the main program. You use SET SCREEN 0. or LEAVE SCREEN. to define the return from the CALL screen.
    Note
    Please consult Data Area and Modularization Unit Organization documentation as well.
    Addition
    ... STARTING AT x1 y1  ENDING AT x2 y2
    Effect
    The coordinates x1, y1 (start column and start line in the window) and x2, y2 (end column and end line in the window) define the size and position of the CALL screen ("top left - bottom right"). Besides these coordinates, you can also see the contents of the primary window, but cannot perform any action there.
    Note
    If "ENDING AT ..." is not specified, suitable values are substituted for x2 and y2, taking into account the size of the called screen.
    Exceptions
    Non-Catchable Exceptions
    Cause: No further screen level (call screen); the maximum number of nested screen levels is restricted to 50 at present.
    Runtime Error: DYNP_TOO_MANY_CALL_SCREENS
    THX

  • How to call parent constructor from subtype body ?

    create or replace TYPE person as object(
    p_name varchar2(10),
    p_age NUMBER,
    p_status CHAR,
    p_addr addr_type,
    constructor function person ( p_name char, p_age NUMBER, p_status CHAR, p_addr addr_type ) RETURN SELF AS RESULT
    )NOT FINAL;
    -- subclass
    create or replace TYPE employee under person(
    e_number number,
    hire_date date,
    e_designation varchar2(15),
    constructor function employee ( e_name char, e_age NUMBER, e_status CHAR,
    e_addr addr_type, e_number NUMBER, hire_date date, e_designation CHAR )
    return SELF AS RESULT
    In this scenario how do we call parent constructor from employee type ?

    Can't You write complete example? Tried few variants but get nothing:(

  • How to call javascript function & action method on clicking jsf  button?

    I have one jsf custom button. I am checking client side validations in mail by calling javascript function & also sending mail by calling action method of a bean which will execute at server side for onclick event of that button. Because of this when I click on that button its calling both javascript function and action method. So even though validations failed its sending mail. How can I overcome this problem?? Please help me....

    I am asking regarding commanLinks in jsf. I have the following code block in jsf. Even though mailSentMessage('true'); returns false, its calling action="#{emailObjectAction.sendEmail}" method. thats why I got that doubt. try the following code.
    <h:commandLink id="mailBtn123Send"      onclick="return mailSentMessage('true');" value="send mail"     action="#{emailObjectAction.sendEmail}">          
    </h:commandLink>

  • How to call Apps Module Custom Method from Entity Object / View Object ?

    Hi All,
    I create a custom method in AppsModuleImpl.java. How can I call that custom method from a setter method on Entity Object / View Object ?
    (I have tried to use Configuration.createRootApplicationModule(amDef,config); but it is not the correct way, is it? )
    Below is my code :
    The setter on MyEntityImpl.java :
    public void setKodeprd(String value) {
    setAttributeInternal(KODEPRD, value);
    if (getProduct() != null) {
    // CALL the getSalesPrice custom method from here, HOW ??
    The Application Module custom method :
    public Number getSalesPrice(String priceCode, String kodePrd) {
    Number price = new Number(0);
    String [] theKey = {priceCode, kodePrd};
    Key priceKey = new Key(theKey) ;
    ViewObject SalesPrice = getSalespricedView1();
    Row[] salesPriceRow = SalesPrice.findByKey(priceKey, 1);
    price = ((SalespricedViewRowImpl)salesPriceRow[0]).getPrice();
    SalesPrice.remove();
    return price;
    Thank you for your help,
    xtanto

    inside the EntityObjectImpl :
    YourAppModuleImpl am = (YourAppModuleImpl)getDBTransaction().getRootApplicationModule().findApplicationModule("YourAppModuleorServiceName");

  • How to call function module/ class method of another system.

    Suppose now i am working in System A. And i need to check the system Status of System B, System C, System D....
    my design is to provide an interface. and each system realize the interface individually.now my question is how cani call the interface, because they are in different systems.
    of course i know about the host name, port and logon information over these systems.
    who can give my some suggestions or other solutions.
    thanks in advance.
    Johnney.

    Hello,
    If u want to call a FM of the other system then that FM should be a RFC enable on one.
    <b>CALL FUNCTION func DESTINATION dest.</b>
    Effect
    Executes the function module from an external source (as a Remote Function Call or RFC); dest can be a literal or a variable.
    Depending on the specified destination, the function module is executed in another R/3 or R/2 System. Externally callable function modules must be flagged as such in the Function Builder (of the target system).
    Since each destination defines its own program context, further calls to the same or different function modules with the same destination can access the local memory (global data) of these function modules.
    To maintain existing destinations, choose Tools -> Administration, Administration -> Network -> RFC destinations
    Note
    Under certain circumstances, an RFC may trigger a database commit. For this reason, RFCs must not be used between pairs of SQL statements that open and close a database cursor (such as SELECT... ENDSELECT).
    Vasanth

  • How to call parent view event or method from popup in java webdynpro

    Hi ,
    I have  view  in my webdynpro component. I created a  button, when i click i am opening  a popup window.
    In side  popup window i am doing some search criteria. I want call a parent view method from popup window and populate search results in parent view table control.I can able to pass the data through context mapping. But i want  a  custom method where i want  to write a code to populate the table control ( i don;t want  to use the wdDoModifyView() method).
    Please help me.
    Thanks
    Aravinda

    Hi,
         The methods in a view are only accessible inside same view. you cannot call it outside the view or
         in any other view although its in same component.
         If you want to have a method in both views, then create the method in component controller and
         from there you can access the method any where in whole component.

  • How to call a custom controller method in a view

    Hi ,
    I am getting the partner no in the custom controller method . I want  to call that method in the view.How is it possible......?

    Hi Masood,
    now i dont want cross compnent navigation ....
    Requirement : Account Identification number in ZVIEW
    My component is  CRMCMP_BPIDENT
    In the custom controller   CRMCMP_BPIDENT/CuCoBuPa  under context node   SEARCHCUSTOMER
    the attribute struct.partner is available 
    in this component  im navigating from  
    CRMCMP_BPIDENT/ObjectCompVs   to   ZCRMCMP_BPIDENT/ZProducts 
    in the layout of   ZCRMCMP_BPIDENT/ZProducts
    TRY .
    lr_cuco ?= controller->get_custom_controller( 'CRMCMP_BPIDENT/CuCoBuPa' ).
    CATCH cx_sy_move_cast_error.
    RETURN.
    ENDTRY.
    check lr_cuco is bound.
    lr_entity ?= lr_cuco->typed_context->SEARCHCUSTOMER->collection_wrapper->get_current( ).
    check lr_entity is bound.
    lv_account_name = lr_entity->get_property_as_string( iv_attr_name = 'BP_NUMBER' ).
    this code is written to get the account identification number but still the same problem
    lr_entity not getting populated .......
    i checked  IF_BSP_WD_HISTORY_STATE_DESCR~IS_RESTORABLE 
    hr rv_result is set to x.....
    any  suggestions....
    Regards,
    Sijo...

  • How to call actionLister after "enforcePreventUserInput" method called

    Hi,
    in my use case i have a table with inputText where i have valueChage Listener method execute and one commadImageLink button(save).
    so i have add glass pane to prevent user input until value chage event is busy. using this tutorial link.
    http://www.oracle.com/technetwork/testcontent/27-long-running-queries-169166.pdf
    and this is working fine.
    problem is when user change some value on input Text and click on save button.
    javascript method call and glass pane popup visible to user until value change event is not completed accepted. but it is skip save button action Listener method.
    i mean actionListener method of save button not executed.
    i want after executing value chage event busy state popup save method is also executed.
    How can i do this?
    regards
    Manish

    Click on the Save button after the valueChangeEvent call has returned implying after the glass pane popup closes. Won't be feasible to invoke two action listeners simultaneously unless Ajax is used for the JavaScript method call from the inputText action method to return.
    Similar to
    <h:inputText id="name" event="" value="#{}">
       <f:ajax listener="#{}" render="" />
    </h:inputText>

  • How to call the backing bean method through javascript by closing window?

    Hi all,
    What I want to do is:
    I open a new page by clicking <t:commanLink.../> from the first page. Then I close the new page. By closing the new page I will call a function in the backing bean such as myBean.doSomething() to do something. Such like:
    <body onUnload=jsFunction()..../>
    ...

    So far I understand, I should write following code
    in my second page:
    <html>
    <head>
    <script type="txet/javascript">
    function jsFunction()
    {>
    ocument.forms[0].action="#{myBean.doSomething}";
    document.forms[0].submit();
    </scrip>
    </head>
    <body onunload="jsFunction()">
    <ui:composition>
    <h:form id="myForm">
    <t:commandLink id="myLink" immediate="true"
    action="#{myBean.doSomething}"
    value=""></t:commandLink>
    </h:form>
    </ui:composition>
    Is that right? I am not sure if I've the javascript
    in the right position.I am sorry! That solution will not work. My Bad.
    You can try this.
    1) Have a invisible command button on your first page with the action attribute set to "#{myBean.doSomething}" as below
    <t:commandButton style="width:0px;height:0px" id="myButton" immediate="true"
    action="#{myBean.doSomething}"
      value=""></t:commandButton>2) Your JS onunload method on the second page should look like
    <script type="txet/javascript">
       function jsFunction()
    var buttonObject= window.parent.document.getElementById("formname:myButton");
    buttonObject.click(); // This would help in submitting the first page
    // to submit to the needed action method
    </script>Karthik

  • How to call different managed bean methods on a page template button

    Dear All,
    Use Case:
    I have a Page Template and inside this page template is a popup screen which is common to all my
    pages. My popup has OK and Cancel button only.
    My question is this, there are lots of pages that uses this template.
    How is it possible to invoke a managed bean methods dialoglistener when say for example the user clicks the OK button?
    One thing common among the pages is that they are included in some kind of a taskflow and I have configured
    a managedbean in a pageflowscope variable in each taskflow and I just wanted to pass the
    My Template
         - TaskFlow 1 (ManagedBean1.dialogListener)
         - TaskFlow 2 (ManagedBean2.dialogListener)
         - TaskFlow 3 (ManagedBean3.dialogListener)
    Each dialog listener does different things.     
    How to do this?
    JDEV 11G PS3
    Thanks

    Found my answer here... http://www.oracle.com/technetwork/developer-tools/adf/learnmore/79-global-template-button-strategy-360139.pdf
    Thanks!

  • How to call a void bean method in a jsp ?

    I want to call a bean method from the jsp page. The method is void i.e it returns nothing.
    Lets say the bean id is mybean and the method name is beanmethod( ). I want to know in what type of jsp tags should I put mybean.beanmethod( ). Using jsp expression <%= mybean.beanmethod( ) %> gives error and so does scriptlet <% mybean.beanmethod( ) %>
    Can someone help me out. Thanx.
    Arshad

    did you already implement this?
    <jsp:useBean id="mybean" class="yourPackage.YourBean scope="session"/>
    use ";" at the end:
    <% mybean.beanmethod(); %>

Maybe you are looking for