Purpose of declaring the method or class or static and as instance

what is the purpose of declaring a method in a class or the class itself as static.
Does it mean we cannot create a copy of that class or method if we declare it as static.
if so then why do they dont want that class to be created as a copy ?
Why do they want to declare a class as static
please provide some conceptual undersatnding regarding the static and instance class with one example

Static methods are often used for the implementation of utility methods. Please have a look at the class CL_ABAP_CHAR_UTILITIES for example.
You use the methods of this class in the same way as you would use a function in ABAP (like
LINES( itab )
). You use it in a static way because the functionality is always the same no matter in what context you are calling the function.
The purpose of instance methods is that their logic is in some way related to an attribute of the object instance that you use to call it.
For example, you create an instance of object PO (a purchase order) called MY_PO. Then the method
MY_PO->ADD_POSITION
would add a position to a concrete PO that has a unique number etc. But if the object has a static method DELETE_POSITION then it just deletes the current position of a PO, regardless on which concrete PO you are acting at the moment.
I hope this clarifies it for you.
Regards,
Mark

Similar Messages

  • The method creates a new object and initializes it...

    Hello there,
    I just started learn the Java, and can't understand the method declaration in "Parameter Types" example at "[Passing Information to a Method or a Constructor|http://download.oracle.com/javase/tutorial/java/javaOO/arguments.html] " tutorial section.
    public Polygon polygonFrom(Point[] corners) {
    // method body goes here
    Can you explain me please the example above, what does "Polygon polygonFrom" means?
    And can it be " the method creates a new Polygon object and initializes it", isn't it Constructor's and the new operator job?
    Thanks a lot!

    869857 wrote:
    public Polygon polygonFrom(Point[] corners) {
    // method body goes here
    }Can you explain me please the example above, what does "Polygon polygonFrom" means?
    Polygon is the return type of the method polygonForm
    And can it be " the method creates a new Polygon object and initializes it", isn't it Constructor's and the new operator job?We can't say that it is a constructor and new operator job. Because, As the return type is Polygon, the method should return an object of Polygon or null. For that purpose only the method needs to create a new Polygon object and initialize with some values.

  • How can I Access the Flash "Slide class" using flex and ActionScript 3?

    Hi,
    I hope someone can help me solve a problem...
    I'm using the flex SwfLoader to load a flash side
    presentation as follows...
    <mx:SWFLoader id="ss_slides" source="ss_slides.swf"
    width="320" height="240"/>
    I would like to access the flash "Slide Class" using flex so
    I can make the following call...
    Slide.gotoNextSlide();
    Anyone know how I can do that?
    Would it be through the SwfLoader Object?
    Is there another way?
    F.Y.I. Here is a snippets about the Slide class from the
    Flash 8 help...
    Using the Slide class (Flash Professional only)
    You use the methods and properties of the Slide class to
    control slide
    presentations you create using the Screen Outline pane for a
    Flash Slide
    Presentation, to get information about a slide presentation
    (for example, to
    determine the number of child slides contained by parent
    slide), or to navigate
    between slides in a slide presentation (for example, to
    create "Next slide" and
    "Previous slide" buttons).
    You can also use the built-in behaviors that are available
    in the Behaviors
    panel to control slide presentations. For more information,
    see Adding controls
    to screens using behaviors (Flash Professional only) in Using
    Flash.
    Thanks,
    Chris S.

    Hi Chris,
    You cannot access the methods of the Flash 8 movie from Flex.
    And you can't do it the other way around either.
    The only way to communicate is to create a LocalConnection on
    each side.
    M.

  • Get a value from the method to class in workflow

    Hi Expert,
         I am doing a workflow and passing a value when submiting  and i need to get the passing value in the Class for further info,
    ****Instantiate an empty event container
      CALL METHOD cl_swf_evt_event=>get_event_container
        EXPORTING
          im_objcateg  = cl_swf_evt_event=>mc_objcateg_cl
          im_objtype   = iv_objtype
          im_event     = iv_event
        RECEIVING
          re_reference = lr_event_parameters.
    *****Set up the name/value pair to be added to the container
      lv_param_name = 'LEVEL'.
      lv_level = wd_this->adlvl.
    ****Add the name/value pair to the event conainer
      TRY.
          CALL METHOD lr_event_parameters->set
            EXPORTING
              name  = lv_param_name
              value = lv_level.
    CALL METHOD cl_swf_evt_event=>raise
            EXPORTING
              im_objcateg        = ls_sibflpord-catid
              im_objtype         = ls_sibflpord-typeid
              im_event           = iv_event
              im_objkey          = ls_sibflpord-instid
              im_event_container = lr_event_parameters.
    I Created a Customised Class zcl_asset and  i need to get the iv_event or  lv_level  value which i passing in the above method to process further to determine the approver in my customised  zcl_asset class.
    Thanks,
    Regards,
    Deeesanth

    >I am doing a workflow and passing a value when submiting and i need to get the passing value in the Class for further info,
    Look, this is not really possible. You cannot pass a value with your code to a class (whatever you mean by this?). With your method you are triggering an event with a parameter. It is possible to "catch" this event and its parameter from workflow. Then your parameter value will be in your workflow and you can use it later (with your class).
    So for example, if you start a workflow with your code, you can create a container element into the workflow, and then with simple binding (in workflow editor) you can get your parameter value into the container element.
    Regards,
    Karri

  • I have iphone 4s , I'm not able to join any wifi, I have tried all the methods, resetting, trying different wifi and many others , but still not able to join any wifi , what shall I do?

    I have iphone 4s , I'm not able to join any wifi, I have tried many things, resetting, trying different wifi and many others , but still not able to join any wifi , what shall I do?

    Contact iTunes support. Nobody here can help with billing problems.

  • GetEnclosingClass method in Class class

    What is the difference between the methods.
    public Class<?> getDeclaringClass()
    and
    public Class<?> getEnclosingClass()
    the second method has been added in jdk5.0
    The two methods seem to be doing the same.

    Anonymous classes aren't declared, so they should be listed in the latter but not the former. Although I haven't actually tried it yet, so you might want to give it a spin...
    D.

  • Static methods inside class in jsp can't make it work

    Hello all i can't understand it why i can't declare the method as static method ?
    public class Request{
              Request(){}
              private String paramValue;
              public static String getRequestParam(HttpServletRequest request, String paramName, String defaultValue){
                   paramValue = request.getParameter(paramName);
                   return paramValue != null ? paramValue : defaultValue;
    im geting this error :
    The method getRequestParam cannot be declared static; static methods can only be declared in a static or top level type
    can't i do inner class ?
    or other sulotion for me not to make instences of class's but to use the class static methods?

    Hi, try this:
    public class Request{
              Request(){}
              private static  String paramValue;
              public static String getRequestParam(HttpServletRequest request, String paramName, String defaultValue){
                   paramValue = request.getParameter(paramName);
                   return paramValue != null ? paramValue : defaultValue;
          }it should work. the problem in you code is that you are trying to referance an non-static object with a static one!
    Message was edited by:
    Adelx

  • Custom iterator problem - The method createChildIterator() is undefined for

    Hi there, this is my first post here, still quite new to Java. I'm having trouble with a custom iterator when trying to test it with JUnit. The reason to write a custom iterator is this: I want to get the object in the array, then for each item I want to get it's child items with a new iterator call.
    It's quite complicated because naturally I'm trying to hide the implementation from the "user". The iterator holds a list of classes called StandardSortElement. Each of these classes holds a class called AvailableResouce
    which in turn holds an AbstractResource, and it's AbstractResource that I want the iterator to return. My JUnit testing shows that this part works correctly.
    For the child items, they are also held inside the StandardSortElement as an array list. Here is the error I get
    "The method createChildIterator() is undefined for the type Iterator<AbstractResource>"
    First here is an interface for the custom iterator:
    public interface SortIteratorInterface extends Iterator<AbstractResource>{
         public abstract Iterator<BookingInterface> createChildIterator();
    }Here is the iterator class:
    public class StandardSortIterator implements SortIteratorInterface {
         ArrayList<StandardSortElement> items;
         Integer position = 0;
         * a constructor that passes in a sorted list of StandardSortElement
         public StandardSortIterator(ArrayList<StandardSortElement> items) {
              this.items = items;
         * Return bookings associated with the currently iterated StandardSortElement
         public Iterator<BookingInterface> createChildIterator() {
              return items.get(position).createBookingIterator();
         * Determine if there is another item in the list
         public boolean hasNext() {
              if (position >= items.size()) {
                   return false;
              } else {
                   return true;
         * Return the next resource in the list. We have a list of StandardSortElement but
         * we want to return the resource within.
         public AbstractResource next() {
              StandardSortElement ssa = items.get(position);                                             // Get a handle on the StandardSortElement     
              AbstractResource ar = ssa.getResource();                                                  // Now get the resource that's packaged up inside
              position++;                                                                                          // Increment the position
              return ar;                                                                                          // return the resource
         * Do not implement - mandatory interface implementation but not required here.
         public void remove() {
              // TODO Auto-generated method stub
    }This is the code taken from the JUnit test class
         * This iterator also has an interal child iterator. Check this works as expected
         @Test
         public void testChildIterator() {
              Iterator<AbstractResource> iterator = new StandardSortIterator(items);
              Integer i = 0;
              while (iterator.hasNext()) {
                   AbstractResource abstractResource = (AbstractResource)iterator.next();
                    if (i.equals(0)) {
                         // The first element should contain children - check it works
                         Iterator<BookingInterface> childIterator = iterator.createChildIterator(); // ERROR OCCURS HERE
                   i++;               
              assertTrue(i.equals(items.size()));
         /************************************************************************************/Thank you in advance for any help you can provide!
    Paul

    Your unit test is coded against the Iterator interface, not your SortIteratorInterface, which is where the createChildIterator method is defined. You need to use a reference to a SortIteratorInterface, not an Iterator. Incidentally, when defining an interface, it's unnecessary to declare the methods as public and abstract. They're implicitly that anyway

  • How can i run a special name method of class?

    i dynamic created a obj
    and i don't know the method of class,
    so i use a String parameter as the method's name
    but how can i run the method?
    please give me a copy of code, thanks!

    import java.lang.reflect.Method;
    public class unknown{
         public static void main(String[] args){
              unknown thisObj = new unknown();
              Class thisClass = thisObj.getClass();
              // calling the method()
              try{
                   Class[] allParamatersType = {};
                   Method mth = thisClass.getDeclaredMethod("method", allParamatersType);
                   String returnCallingAdd = (String)mth.invoke(thisObj, null);
                   System.out.println("calling add() : " + returnCallingAdd);
              catch(Exception ex){
                   ex.printStackTrace();
              // calling the method(int , string)
              try{
                   String firstValue = "Testing";
                   Class[] allParamatersType = { firstValue.getClass() };
                   Object[] values = { firstValue };
                   Method mth = thisClass.getDeclaredMethod("method", allParamatersType);
                   String returnCallingAdd = (String)mth.invoke(thisObj,values );
                   System.out.println("calling add() : " + returnCallingAdd);
              catch(Exception ex){
                   ex.printStackTrace();
         public String method(){
              return "method() called";     
         public String method(String two){
              return "method(String) called";     

  • Class-data versus data and methods versus class-methods in OO ABAP

    Hi
    I was going thorugh following OO ABAP code.
    CLASS vessel DEFINITION.
      PUBLIC SECTION.
        METHODS: constructor,
                 drive IMPORTING speed_up TYPE i,
                 get_id RETURNING value(id) TYPE i.
        CLASS-METHODS: start,
                       objects,
                       inheritance,
                       interfaces,
                       events.
      PROTECTED SECTION.
        DATA: speed TYPE i,
              max_speed TYPE i VALUE 100.
      PRIVATE SECTION.
        CLASS-DATA object_count TYPE i.
        DATA id TYPE i.
    ENDCLASS.
    Whats is difference between methods and class-methods ?
    What is the difference between data and class-data ?

    Hi Rajesh,
    There are two types of componenets in a class
    1)Static components
    2) Instance components
    Instance components exist for every instance of the class, while static exist only once for any number of instances of the class.
    Components of the class are methods, attributes, events etc.
    static attributes are represented by CLASS-DATA and instance attributes are represented by DATA.
    static methods hence are done by CLASS-METHODS and can access only static attributes.
    Instance methods are done by METHODS and can access any attribute.
    For eg: supposing that in a class, there is a static attribute. Suppose after one instance is created, we are setting this static attribute value as 10. Now we are creating another instance of the same class. Now when you try to display the value of this attribute, it will be 10.ie. it needs to be initialized once and can be shared between instances.
    Just go through this document..You will get nice info from this.
    http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
    http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
    If you want to go deeper, like object persistence and all, just refer this document.
    http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
    Regards,
    SP.

  • Method addTextUrlColumn (Class oracle.jbo.html.databeans)

    The method addTextUrlColumn (Class oracle.jbo.html.RowSetBrowser) adds an additional column to the View's RowSet. This column will be appended after all of the colummns that represent attributes belonging to the RowSet. How can I insert a additoinal column before all of the columns of the RowSet instead?
    Thanks
    Yoo

    The RowsetBrowser doesn't support this by default, you have source code to this control. You can extend it's features by adding this capability. Look at the source code in bc4jhtmlsrc.zip

  • Printing java object in the method

    How to print the object that has called the method in the method itself.
    class abc{
    public method1()
    S.o.p("Print the object that has called this method")
    psvm(string a[])
    abc aa=new abc();
    aa.method1();
    Thanks
    Sir

    Or make a new exception and parse the stack trace.
    This has a performance penalty, though.That wont get the object that's making the call (the 'this' of the method that's making the call), but only the class and the method

  • The method "main"

    which class the method "main" belongs to ? and how java behaves with the method "main" ?

    Z.S.Tehrani wrote:
    which class the method "main" belongs to ? main belongs to the class that you put it in, it is just another method and is only special in that the Java can use it as an entry point to your application.
    and how java behaves with the method "main" ?Java behaves with main and any other method, just exactly how you have programmed it to act. The only difference being that main can be used by Java an the entry point to your application.

  • Which object called the method

    Suppose there is a class A which has three objects a1,a2,a3 and a method m. Now I'd like to know which particular object has called the method m.

    >
    which particular object has called the method
    What class called my method
    http://developer.java.sun.com/developer/qow/archive/104
    a.The advice in the posted link is unreliable as the format of printStackTrace() is not standardized. A more reliable way to find out the calling class is to use SecurityManager.getClassContext() or Throwable.getStackTrace() [in JDK 1.4+].
    However, it is not clear whether the original poster wanted to know the calling class or the calling object. In the latter case there is no easy way except for modify the signature of method m to accept the reference to the calling object.
    Vlad.

  • User message in the method "executeQueryForCollection"

    Hi everyone,
    I pray you excuse my english.
    I am working in jdev 11.1.2.1.
    I have an "adf:inputListOfValues" in a "jsf".
    In the search popup, I would display a message to the user if search criteria are not informed.
    To achieve this, I implemented the method "executeQueryForCollection" of the "VO" to launch a "JboException".
    At run time, the first time I perform a search user, it displays correctly. But, any other action causes an exception of type "nullPointerException".
    In the ADF source code, the method "ViewRowSetImpl::execute" calls to "executeQueryForCollection" method. The method "ViewRowSetImpl::execute" catch exceptions and the object instance "queryCollection" is initialized to "null". This fact throws the exceptions of type "NullPointerException".
        "catch (Exception e)
                setQueryCollection(null);
                if (e instanceof JboException)
                   throw (JboException) e;
                else
                   throw new JboException(e);
    I prefer not to add a message of "FacesMessage" type in the data model.
    Is there any other way to show this message to the user?
    Thank you very much.

    Hi,
    sandip is correct, go to SE11 Table T100.
    I did it this way: Searched for (in my case) SPRSL = DE and TEXT = "Bitte Bankschlüssel eingeben" (that's the said error message). With the upcoming result I got the message ID and message Number, these are:
    ARBGB = 'AR' MSGNR = '195'
    ARBGR = '1J' MSGNR ='510'
    Maintain them for your SPRSL and you should be fine.
    regards, Lukas

Maybe you are looking for