Explizit using methods of base class

when using a base class reference from an abstract class A and creating an object of subclass B
A ref_A = new B();
assuming we have implemented the method m() in A and B, then
ref_a.m()
calls Method m of subclass B
(dynamic binding, fine)
Is there a possibility to force explicitely the call of method m of superclass A.
(i mean not a call from Method m in B with super())

are you absolutely sure ?I am sure. Perhaps you are thinking of C++ (and if you're not, I am!) where you can write: ref_A.A::m(),
but there's no way from the client code to do that in Java. If you really need to do this, your
design of A should reflect it:
public abstract class A {
    public final void mOldSchool() {...}
    public void m() { mOldSchool(); }
public class B extends A {
    public void m() {...}
}I agree with Kayaman, though: question your design. In the abstract, this is a shakey design.

Similar Messages

  • Use methods of another class

    Dear Sir/madam,
    i have a question about using methods of another class. I will explane:
    i have made a class which is called A. This class has some attributes (studentName and examRank) and some methods.
    Now i need to made another class called B. Now i want to make an array where i can add some attributes of objects which i made of class A. How can i do that?
    Kind regards

    Here's a for-instance that doesn't use your exact program but demonstrates the point:
    public class A
      int value;
      String name;
      public A(int value, String name)
        this.name = name;
        this.value = value;
      public int getValue()
        return value;
      public String getName()
        return name;
      public String toString()
        return name + ": " + value;
    import java.util.Arrays;
    import java.util.Random;
    public class B
      private static final String[] NAMES =
        "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
      private static final int MAX = 100;
      private A[] myAs = new A[NAMES.length];
      private Random random = new Random();
      public B()
        for (int i = 0; i < myAs.length; i++)
          myAs[i] = new A(random.nextInt(MAX), NAMES);
    public String toString()
    return Arrays.toString(myAs);
    public int getTotal()
    int temp = 0;
    for (int i = 0; i < myAs.length; i++)
    temp += myAs[i].getValue();
    return temp;
    public static void main(String[] args)
    B b = new B();
    System.out.println(b);
    System.out.println("Total: " + b.getTotal());

  • Use methods in other classes

    Can I use methods from other classes than the class that myClass extends?
    ex. myClass extends parentClass{
    myMethod()
    myMethod() is declared in i third class. Is this possible or can I only use classes from the parent class?
    -Thanks-

    I'm not really sure what the previous two answers were getting at.
    Yes, you can use methods all the way up the class hierarchy, as long as they are visible.
    For example, Object implements toString(). You can call toString() on any object in Java and it will render the object to a string in one way or another. That is because toString() is public.
    If toString() were protected, you would only be able to call the method if you were a subclass of of that object (or in the same package), which would make the toString() method much less useful.
    I would suggest reading up on the differences in the four visibility modifiers (private, (default), protected, and public). Private is the only one which nothing else can call. If you are public or protected, any subclass can call the method, even if there are 20 superclasses between the implementor and the caller.
    Good luck!
    Steve

  • Error in using method get_event of class cl_htmlb_manager.

    Hi All,
    i am trying to get the event details in a particular method as follows;
    data: event type ref to cl_htmlb_event .
    event = cl_htmlb_manager=>get_event( runtime->              server-  >request ).
    i am getting an error
    field RUNTIME is unknown , it is neither in one of the specified tables nor defined by DATA statement. DATA statement. DATA statement.
    Where am i going wrong?
    plz help.
    BR,
    Annu.

    Hi Jorge,
    I am trying to use it in the method GET_LIST of class CL_SUS_M_ORDER_LIST .
    If i use
    event = cl_htmlb_manager=>get_event_ex( request ).
    again i get the error  Field REQUEST is unknown .
    and if i dont declare event using data statement
    data: event type ref to cl_htmlb_event .
    then i get the error that Field EVENT is unknown.
    My application is MVC pattern.
    So is there anyother way of geting the EVENT details when RUNTIME / REQUEST are not available ?
    Thaknks for the reply.

  • Transaction code which using method of a class as start object

    Hi all,
    I'm creating a new tcode 'Z123' which is tied to a method of a class in SE93. However, when I run this tcode and into debug mode, SY-TCODE will always return OS_APPLICATION. How can I get the actual tcode, which is 'Z123' into my program?
    Thanks in advance

    You can try using the method GET_CURRENT_TRANSACTION of class CL_DYNPRO. Check this SAP documentation for details:
    ... the method GET_CURRENT_TRANSACTION of the class CL_DYNPRO can be used to obtain the transaction code of the current transaction. This method returns the transaction code during a parameter transaction or variant transaction instead of the transaction code of the implicitly called dialog transaction.
    But if i try checking sy-tcode in a tcode bound to a method of a class i get the correct tcode & not OS_APPLICATION.
    Br,
    Suhas

  • Use method from father class for event

    Hi,
    I want to use a preDelete event in my class, but the method I would like to call for the event is not in the class itself, but in the (abstract) predecessor class. Any chance to do this? At the moment I can't select the method in the event tab page (it's not in the list to choose from ...)
    Thank you!
    J.F.

    In 9.0.4 you will need to add the parent class as a descriptor and choose to deactivate it. This will allow you to choose methods from that class in the subclass descriptors.
    In 10.1.3 there is a dialog for specifying classes that are not persistent, but necessary in other persistent classes: http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/mw007.htm#sthref629
    A good explanation of why we don't store the parent and referenced classes unless explictly asked can be found here: Re: Mapping Workbench  10.1.3.0 Bug - Cannot add Implemented Interfaces
    Hope this helps,
    Karen

  • How to use method of Standard Class

    Hi all,
                  I want to call a pop up in pcui screen in some standard application with some text. I have made Zclass of  standard SAP class which i am using (cl_bsp_accmod_contact in CRM system).
    I think i have to call 'PRINT_STRING' method of  standard class CL_BSP_ELEMENT.
    <i>I am trying to use this code: </i>
    <b>
    data: lr_data type ref to cl_bsp_element.
      concatenate html 'rohit' into html.  (html is a string)
      lr_data->print_string( html ).</b>
    <u>but it gives a dump:</u>
    You attempted to use a 'NULL' object reference (points to 'noth
    access a component (variable: "lr_data").
    An object reference must point to an object (an instance of a class)
    before it can be used to access components.
    I dont know how to assign object reference to an object???
    Plz help me in this regard,
    Thanks in advance,
    Rohit

    Hi ,
    try and use :
    data: lr_data type ref to cl_bsp_element.
    concatenate html 'rohit' into html. (html is a string)
    lr_data->print_string( html = html ).
    You are creating a variable...but not passing the value to the parameter...it is exactly like callin get_data or get_cell_value...!!
    Hope this helps.
    <i><b>Do reward each useful answer.</b></i>
    Thanks,
    Tatvagna.

  • Adding methods to base classes

    How are new methods proposed and adopted for the base classes?

    Your question is unclear and I doubt if it has anything to do with JNDI.

  • How to use method of one class in other class.

    Hi.I am new to object orient approach .I am developing a project which has a class as application .My class has it state control as another class which is notification class.I want to use my notification class method (init)in my application class method .i have also used read and write accessors vis.But i have broken lines in my code.Please help me correct it. and print screen is attached below.
    Attachments:
    Application.docx ‏143 KB

    On the left, you have wired 2 sources on the same tunnel/wire, so that's 1 broken wire.
    In the For loop, you are trying to wire a "Red" object from the first subVI to the input of the "Green" subVI, so a "Green" object. If Red is not a descendant class of Green (or share a common ancestor), it is not permitted.
    FInally, the output of the For loop, is a 1D array of "Green" objects, which is probably not the same data type as the input of the last subVI on the right (it's probably a "Green" object scalar).
    Overall, you can use the "List Errors" dialog box (Ctrl+L) to debug your code, and make exhaustive use of the contextual help (Ctrl+H) to see what is going on when focusing a broken wire.
    Regards
    Eric M. - Application Engineering Specialist
    Certified LabVIEW Architect
    Certified LabWindows™/CVI Developer

  • Implement abstract method from base class problem

    Here is the example:
    public abstract class AbstractClass{
    protected double aVariable;
    protected abstract double abstractMethod();
    public class RealClass extends AbstractClass{
    public double abstractMethod(){
    return aVariable;
    Error message:
    RealClass should be declared abstract; it does not define abstractMethod() in AbstractClass

    I also compiled the code with Jdk1.3 and it
    worked.. The code would not have compiled
    if the access modifier in the derived class
    was more restrictive(eg private )...

  • How to specify a base class for Remote Interface in Workshop 9.2? -- URGENT

    Hi,
    I am trying to create a UUP EJB in WebLogic 9.2 workshop. I am using @FileGeneration to create my home & remote interfaces. And the generated remote interface is extending javax.ejb.EJBObject;I want my remote interface to extend com.bea.p13n.property.EntityPropertyManager which in turn implements javax.ejb.EJBObject. Can someone tell how i can do it in Workshop?.
    I came across Predefined Variable: remote.baseClass and as per docume
    ntation..."If specified, the value of this variable will be used as the base class for all generated remote classes. Where i should specify it?. @FileGeneration does nt have any option for it. Any help is grtly appreciated.
    Following are my code snippets:
    IMPL Class
    @FileGeneration(remoteClass = Constants.Bool.TRUE,remoteHome = Constants.Bool.TRUE, localClass = Constants.Bool.FALSE, localHome = Constants.Bool.FALSE,remoteClassName = "MyEntityPropertyManager",remoteHomeName = "MyEntityPropertyManagerHome")
    public class MyEntityPropertyManagerImpl extends GenericSessionBean implements
              SessionBean {
    //code
    }

    This question was posted to both the bea.workshop.developer.general and weblogic.developer.interest.workshop (I had replied to the later on 10/19); after seeing an identical question today on this list want to include a reference to that reply here:
    http://forums.bea.com/bea/message.jspa?messageID=600044925&tstart=0
    -Rob

  • How to create search function (af:query) using method in java

    hi All..:)
    i got problem with search custom (af:query), how to create search function/ af:query using method in java class?
    anyone help me....
    thx
    agungdmt

    Hi,
    download the ADF Faces component demo sources from here: http://www.oracle.com/technetwork/testcontent/adf-faces-rc-demo-083799.html It also has an example for creating a custom af:query model
    Frank

  • Export for AS: Class vs Base Class

    when i export a movie clip for actionscript, what are the differences between Class & Base Class?  i see most tutorials change Base Class and leave Class as the name of the movie clip defined in the library.

    the main use of the base class is to extend it so many different classes can share it's functionality.
    but even when not needed as a super class, the base class is also helpful when you want to instantiate many different objects using code and you don't want to write/compile many different class files.
    if flash finds you failed to write a class file (for every class exported for actionscript), flash writes a default class files for you.

  • The method clearCaches() in class Utility

    to anyone who read this topic,
    I want to clean caches using method clearCaches() in class com.sun.corba.se.impl.util.Utility, but I find there are some discriptions in method definition, it is "Clear the stub/tie caches. Intended for use by
    test code".
    Do this mean it is only for test code usage? very appreciate if anyone could tell me if I can use this method in my code? Does it bring some other impacts if I use it?
    Very thanks,
    Chris
    Software engineer
    Notel

    Hi.
    That's right. according to paramter locator, you will gain interfaces interfaces(Bouquet, Network, ProgramEvent, ProgramEventDescription, ServiceComponent, ServiceDescription, ServiceDetails, SIElement, TransportStream) implements SIRetrievable.
    I will notice you that "SIRequest" returned is for "going" or "canceling". if you get something, it will get parameter "SIRequestor" interface.
    I hope to help you.
    YongHwan

  • Problem using method CMD_EI_API_EXTRACT= GET_DATA

    Hi all
    I was trying to get customer's  all detail data using method GET_DATA of class CMD_EI_API_EXTRACT.
    but the data i get is all initial.  it means i get no data.
    Is any one know the problem?, please tell me Thanks.
    my code is like below.
    DATA:
          L_IS_MASTER_DATA TYPE CMDS_EI_MAIN,
          L_ES_MASTER_DATA TYPE CMDS_EI_MAIN,
          L_ES_ERROR TYPE CVIS_MESSAGE.
    DATA: T_CUSTOMERS TYPE CMDS_EI_EXTERN_T,
          S_CUSTOMERS TYPE LINE OF CMDS_EI_EXTERN_T.
    DATA: T_COMPANY TYPE CMDS_EI_COMPANY_T,
          S_COMPANY TYPE LINE OF CMDS_EI_COMPANY_T.
    DATA: T_SALES TYPE CMDS_EI_SALES_T,
          S_SALES TYPE LINE OF CMDS_EI_SALES_T.
    S_CUSTOMERS-HEADER-OBJECT_INSTANCE-KUNNR = '002000013'."customer No
    S_CUSTOMERS-HEADER-OBJECT_TASK = 'M'.
    S_COMPANY-DATA_KEY-BUKRS = '2000'." Company code
    APPEND S_COMPANY TO T_COMPANY.
    S_CUSTOMERS-COMPANY_DATA-COMPANY = T_COMPANY.
    S_SALES-DATA_KEY-VKORG = '2000'."sales ORG
    S_SALES-DATA_KEY-VTWEG = '10'." distribution channel
    S_SALES-DATA_KEY-SPART = '00'." divsion
    APPEND S_SALES TO T_SALES.
    S_CUSTOMERS-SALES_DATA-SALES = T_SALES.
    APPEND S_CUSTOMERS TO T_CUSTOMERS.
    L_IS_MASTER_DATA-CUSTOMERS = T_CUSTOMERS.
    CALL METHOD CMD_EI_API_EXTRACT=>GET_DATA
      EXPORTING
        IS_MASTER_DATA = L_IS_MASTER_DATA
      IMPORTING
        ES_MASTER_DATA = L_ES_MASTER_DATA
        ES_ERROR       = L_ES_ERROR.

    Hi Sheik, Thank you for your reply.
    I've checked the internal tables and i get the data in the internal tables is initial.
    why i using XXXX type CMDS_EI_*_T to create internal table is i just wanna fill  the internal table L_IS_MASTER_DATA up with
    select condtion data.
    best regards.
    Edited by: alex.lee on Sep 27, 2010 2:39 AM
    Edited by: alex.lee on Sep 27, 2010 2:40 AM

Maybe you are looking for