Declaring a method

why do we need to make a method private as well as final in
private static final methods

if we declare a method as private then that method can't access in other classes even in subclasses also.
if the method declare as final then that method can't overridden in sub classes
if the method declare as static the only one instance is enough for as
ex: we can call that method in sub classes without creating the object of the super class.
class a
static void method1()
System.out.println("in super class");
class b extends class a
Public static void main(String a[]);
method1();
it will print in super class as out put.

Similar Messages

  • 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

  • Why interfaces can not declare static methods?

    Why interfaces can not declare static methods?

    Why are you shouting?
    Is your internet broken?
    [http://www.google.co.uk/search?q=interface+static+methods+java] 2,440,000 hits.

  • Declaring static methods.

    I have some questions about declaring a method as static. If I first write a paragraph about my understanding so far, followed by a code snippet hopefully somebody can help me out.
    It is my understanding (limited) that only one class is loaded by the classloader. When creating an object, all its parameters are stored, but each object does not have its own copy of the methods its class defines, each method. If a method is declared as static then you do not have to create an instance of this class to call this method.
    Code
    /** Get table of codes.
          * @return <code>Hashtable</code> populated with clinical code values.
        public Hashtable getCodeHashtable(HttpServletRequest request) {
            Hashtable htResults = new Hashtable();
            try {
                SpParameter[] spOut = {
                    new SpParameter(OracleTypes.CURSOR, 0)//po_cur_data
                 HOUtils utils = new HOUtils();
                UtilDBquery db = utils.getUtilDBquery(request);
                htResults = db.runGeneralStoredProcedureThrowsExceptions(null, spOut, SP_CodeList, null, true, true);
            } catch (Exception e){
                 e.printStackTrace();
            return htResults;
    Questions
    1) If each object does not carry around its own copy of the methods associated with its class, how does the jvm know which object is calling a method?
    2) In the above code snippet, if I were to make the method static would this have implications if 2 people were to browse to the same page on the app server and run this method at the same time?
    Thanks for any replies.

    1) If each object does not carry around its own copy of the methods
    associated with its class, how does the jvm know which object is
    calling a method?Each object stores one single pointer to its class description. The class
    description contains all the methods (also the static ones). This is a bit
    of a simplification but basically that's all there is to it. When you call
    a method, the address of the method is looked up in that class description
    and it's invoked. For non static methods there's a hidden parameter,
    called 'this' so the method always 'knows' which object it (the method)
    is invoked on. For static methods that hidden parameter simply isn't
    present.
    2) In the above code snippet, if I were to make the method static
    would this have implications if 2 people were to browse to the same
    page on the app server and run this method at the same time?Who knows? This all depends whether or not the method (static or not)
    is reentrant, i.e. does the method have side effects? Does the method
    needs to be synchronized?
    kind regards,
    Jos

  • Strange about invoking web service method declared “string  method(void)”;

    Dear forum readers
    I’m experimenting with OpenESB and web services. I’ve create a simple web service using NetBeans 6.1. The method consists of a single method, getTime, that is declared:
    String getTime()
    My current experiment is to invoke this method from a BPEL-process using the “Invoke” process object. The strange thing is that it seems like I have to provide a “dummy” inbound variable from the BPEL-designer even though the method doesn’t take any parameters. I include a snippet from the BPEL process below which includes the section where I set the dummy GetTimeIn-variable and then invokes the WS method getTime().
    <assign name="Assign2">
    <copy>
    <from>'DummyValue'</from>
    <to variable="GetTimeIn" part="parameters"/>
    </copy>
    </assign>
    <invoke name="Invoke1" partnerLink="PartnerLink1" operation="getTime" xmlns:tns="http://ws/" portType="tns:MyWebService" outputVariable="GetTimeOut" inputVariable="GetTimeIn"/>
    If I don’t initiate the dummy variable or remove it altogether, I can’t successfully call the method. If I include the dummy in-parameter the call works just fine and I get back the current time as a string.
    I must admit that I’m still a rookie to web services, especially when calling them from a BPEL-process, so it may be a very trivial reason for this behaviour. Anyway, any help on this matter would be greatly appreciated.
    Regards, Ola

    Thank you both for the response. Regarding Rennay’s posting I have an additional question. When I create a new web service I don't have the "Document Literal" option nor a "Concrete Configuration" tab. I've created the web service using the "Web Application" project type and then adding a web service using the "Web Service..." wizard. This wizard doesn't have the configuration properties you mention, but if I add a WSDL-file to a BPEL-project the wizard has the properties you mention.
    Is it possible to create a web service, programmed as an ordinary Java-class, from an existing WSDL-file? In that case it may solve the problem with the “Document Literal” property. Currently I don’t know any other way to create such a web-service other than the through the web service wizard in a web application project. Of course, it’s possible to craft it from scratch but that’s to much work to be practical.
    Regards, Ola

  • How to declare abstract method

    given - work worked at first .
    fact - then i went to add new entity object names ScottOafE0 . went through all the next sand finished. a package and entity obj already exist. i also tried to put a new package and ScottOafAM in a seperate place. still a no go
    when i went to run the form it errors out w/ below msg.
    Error(14,8): class xxxoaf.oracle.apps.xxuab.hr.newforms.server.ScottOafEOImpl should be declared abstract; it does not define method setLastUpdateLogin(oracle.jbo.domain.Number) in class oracle.apps.fnd.framework.server.OAEntityImpl
    Guess - i tired to put import oracle.apps.fnd.framework.server.OAEntityImpl in the controller file . didnt work
    any idea how to define abstract method ?
    thanks
    scott

    You dont need to define your class as abstract, that would not resolve your issue, what is happening is
    oracle.apps.fnd.framework.server.OAEntityImpl is a abstract class, and has a method declared as setLastUpdateLogin(oracle.jbo.domain.Number) in class
    Now, any class (xxxoaf.oracle.apps.xxuab.hr.newforms.server.ScottOafEOImpl ) extending from this class must either provide a definition to this method (provide the implementation logic), or must itself be declared abstract.
    We had a discussion on this issue in the forum , look for the thread.
    Thanks
    Tapash

  • Error with declaring a method with array variable

    Hi,
    I had implemented this:
    import java.awt.*;
    import javax.swing.*;
    public class Oefening1
         public static void main(String args[])
              int array[]= new int[10];
              int getal;
              JTextArea outputArea = new JTextArea();
              Container container = getContentPane();
              container.add(outputArea);
              public void invoerRij(int array[10])
                   output +=" ";
                   for(int counter = 0; counter <10;counter++){
                        output +="Geef een getal in"+"\n"+array[counter]+"\n";
                        outputArea.setText(output);
    I had comilated this code while the compiler gave errors like these:
    A:\Oefening1.java:15: illegal start of expression
              public void invoerRij(int array[10])
    ^
    A:\Oefening1.java:24: ';' expected
    ^
    A:\Oefening1.java:12: cannot resolve symbol
    symbol : method getContentPane ()
    location: class Oefening1
              Container container = getContentPane();
    ^
    3 errors
    Tool completed with exit code 1
    Now i have read my book and finded out that the declaration of a method always starts with public.
    Can anyone halp me solving these probs? Thanks
    Crazydj1

    The problem is that you didn't close the previous method definition.
    Compiler error messages (in any language) often mistakenly report false errors on perfectly valid code immediately following the actual error.
    When you post code on these forums, please wrap in in &#91;code]&#91;/code] tags.

  • Declaring constructor method public or private.  What's the point?

    My book declares the constructor method public. I tried declaring it private, and without any modifier out of curiousity. It runs exactly the same. What's the point of doing so?
    public class test
         public static void main( String[] args )
              test fun = new test();
              test fun2 = new test(2);     
              System.out.println( fun );
    //          System.out.println( test.toString() );
         public String toString()
              return "This is the toString";
         test()
              System.out.println( "This is the constructor method" );
         test( int x )
              System.out.println( "This is the constructor method: " +x );
    }

    yougene wrote:
    I'm new to OOP so maybe I'm not completely grasping the terminology. But this program works just fine with my class.
    public class test2
         public static void main( String[] args )
              test foo = new test();
    }It gives me the following output
    ----jGRASP exec: java test2
    This is the constructor method
    ----jGRASP: operation complete.The constructor method is executing from an outside class. I tried this with and without the private modifier on the constructor. Same result.Try compiling this.
    public class C1 {
      private C1() {
        System.out.println("C1 c'tor");
    public class C2 {
      public void foo() {
        C1 c1 = new C1();
    }

  • How declara a method in my jsp code?

    I have the following method.
    Somebody knows as there is to declare it in my jsp code?
    Thanks.
    public String reemplaza(String i,String ci,cf)
    String o=i;
    while(o.indexOf(ci)!=-1)
    { o=o.substring(0,indexOf(ci))+cf+o.substring(indexOf(ci)+ci.length(),o.length()); }
    return o;
    }

    Compare the codes and you see the errors.
    //Before(with errors)
    public String reemplaza(String i,String ci,cf)
    String o=i;
    while(o.indexOf(ci)!=-1)
    { o=o.substring(0,indexOf(ci))+cf+o.substring(indexOf(ci)+ci.length(),o.length()); }
    return o;
    //After(with no errors):
    public String reemplaza(String i,String ci,String cf)
    String o=i;
    while(o.indexOf(ci)!=-1)
    { o=o.substring(0,o.indexOf(ci))+cf+o.substring(o.indexOf(ci)+ci.length(),o.length()); }
    return o;

  • Exception declaration for methods in a Controller

    Hi all enthusiasts of WD,
    me again :-). I just noticed that one cannot declare exceptions thrown by a public method in a controller. Is it on purpose to shut down exception handling?
    Maybe it makes sense to forbid this for the component interface controller, since the interface controller is accessible outside the component, it's not a good idea to ask other components to handle the exceptions specific to one component (after all, a component should be a self-contained unit); but for other controllers like component controller, it's convenient and safe to allow exception declaration --- it can only be accessed inside the component anyway.
    Will this be supported in the future? Thanks.
    Best regards,
    Ge

    Ge,
    You misinterpreted my answer a bit.
    1. Create own subclass of RuntimeException so you may distinguish your exceptions and standard ones like NullPointerException, ArrayIndexOutOfBoundsException:
    public class GeRuntimeException extends RuntimeException {
      public GeRuntimeException(final String message) { super(message); }
      public GeRuntimeException(final Throwable cause) { super(cause); }
      public GeRuntimeException(final String message, final Throwable cause) { super(message, cause); }
    2. Next create concrete sublcasses of your superclass:
    public class GeSecurityException extends GeRuntimeException {
    public class GeDatabaseException extends GeRuntimeException {
      public GeDatabaseException(final java.sql.Exception cause) { super(cause); }
    3. Typical code pattern that throws your exception:
    final PreparedStatement pstmt = ...;
    try {
      pstmt.setInt(1, 0);
      pstmt.setString(2, "String param");
      pstmt.executeUpdate();
    } catch (final SQLException ex) {
      throw new GeDatabaseException(ex);
    4. Typical code pattern that handle exception:
    try {
      wdThis.wdGetOtherController().makeDatabaseCall();
    } catch (final GeDatabaseException ex) {
      wdComponentAPI.getMessageManager().reportException(
        new WDNonFatalException( ex.getCause() ), false
      return;
    } catch (final GeRuntimeException ex) {
      wdComponentAPI.getMessageManager().reportError("Unexpected failure");
      return;
    /* Some other code if no exception */
    Notice that code above does not catch generic RuntimeException, only your sublcasses.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • Reg: declaring classes, methods, objects

    Hi,
    Can anyone help me on how do i declare classes and methods in webdynpro. My requirement is to do some functionality in a method of a class and reuse the code wherever i require.
    Can anyone help me on this?
    Thanks
    Regards
    Naveen

    Hi Naveen George ,
                           You can create methods in both component controller and on each view also.
    methods dexlaring in comp controller will be common among all view
    you can call comp controller method like comp_controller->method name in other view
    and own methods can be called like wd_this-> method name.
    you can also use wizard to call methods
    for calling own methods you have to select current controller radio button and for comp_controller you hacve to use used controller.
    you can create method by going to method tab both in view and component controller
    Regards
    Sarath

  • Declare a method

    Hi All,
    I am writing code to populate a key figure in a structure. The formula is like:
    kf1 = nodim(  kf2 ) * kf3.
    nodim is a function - Value Without Dimension (Unit-free). This is used in a query to calculate a key figure. My requirement is to simulate the functionality in the code.
    How to declare or define the method or function 'nodim'?
    Please advise.
    Message was edited by:
            Sachin Guptha

    Hi Sachin,
    possibly I don't understand in depth what you are going to do.
    You said
    kf1 = kf3 + kf4.
    and
    code for kf1 already exists in a method.
    Does the method do the addition of kf3 + kf4? what's the method's name and where is it declared? Where do kf3 and kf4 come from?
    Still I don't know what the nodim function is going to do. nodim is used for dimensionless. What does thius mean in your contect? And where does kf5 and kf6 come from?
    CLASS definition and implementation can be written anywhere in your program or defined in the class builder making it reusable.
    I think the question is: if the implemented method is thought for populating the second key figure (kf2), then how to populate values (parameters?) kf5 and kf6 and how to interpret nodim function - is it just the decimal value of an exponential number a.bcdeEnn or what?
    Could you please explain the circumstances of the task (in other words: What the hell are you doing?)
    Kind regards,
    Clemens

  • Af:AutoSuggestBehavior declaring suggestItems method dynamically

    Hi,
    In our application we generate set of input text fields dynamically. We want to have auto suggest behavior for some of them and want to generate the auto suggest handler dynamically.
    For example in the code
    <af:iterator id="i3" value="#{pair.attributes}"
    var="criterion" varStatus="vs2">
    <af:switcher id="criteriaSwitcher2"
    facetName="#{criterion.attribute.componentType}"
    rendered='#{criterion.additionalInfo.type == "attribute"}'>
    <f:facet name="inputText">
    <af:group id="g3">
    <trh:cellFormat halign="right">
    <af:outputLabel value="#{criterion.attribute.label}"
    id="textLabe"/>
    </trh:cellFormat>
    <trh:cellFormat>
    <af:selectOneChoice id="textCriterionOperator"
    value="#{criterion.operator}" >
    <f:selectItems value="#{criterion.operators}"
    id="nameCriterionOperators"/>
    </af:selectOneChoice>
    </trh:cellFormat>
    <trh:cellFormat>
    <af:inputText id="textInput"
    value="#{criterion.values[0]}"
    *<af:autoSuggestBehavior*
    *suggestItems="#{criterion.suggestMethod}"/>* </af:inputText>
    </trh:cellFormat>
    </af:group>
    </f:facet>
    </af:iterator>
    The criterion.suggestMethod holds EL expression for the actual suggest implementation method. If I give like above, ADF is thinking that criterion.suggestMethod is the actual suggest handler and complaining that no such method exists. How can I achieve this dynamic behavior?

    No. I want this dynamically meaning for Criteria1, the handler is onSuggestCriteria1 and for Criteria 2, the handler is onSuggestCriteria2. I have these defined in the Criertia.suggestMethod variable as an EL expression.
    For example, the Criteria object for Criteria1 will have #{SuggestBean.onSuggestCriteria1} and Criteria object for Criteria 2 will have #{SuggestBean.onSuggestCriteria2}.
    I would like to get these ELs evaluated and represented as below
    For example
    <af:inputText id="textInput"
    value="#{criterion.values[0]}"
    <af:autoSuggestBehavior
    suggestItems="#{criterion.suggestMethod}"/> </af:inputText>
    Should gete translated to some thing like this for criteria1
    <af:inputText id="textInput"
    value="#{criterion.values[0]}"
    <af:autoSuggestBehavior
    suggestItems="#{SuggestBean.onSuggestCriteria1}"/> </af:inputText>
    and
    some thing like
    <af:inputText id="textInput"
    value="#{criterion.values[0]}"
    <af:autoSuggestBehavior
    suggestItems="#{SuggestBean.onSuggestCriteria2}"/> </af:inputText>
    for criteria 2.
    Hope now it is clear.
    Thanks

  • Declaration of Rabge table Paramater in Global class method

    Hi Friends,
    I have created a Global class with a method GET_DATA.
    In that method,i have written the like  :
    select * from kna1 into table it_kna1where kunnr in S_kunnr.
    But, I am getting the error with Range table S_KUNNR.
    Kindly, Let me know how I should Declare S_KUNNR in parameter list of GET_DATA,  what should be its associated data type?
    Regards,
    Xavier.p
    Edited by: Xavier on Jul 16, 2009 3:50 PM

    1) Create a Public Type for ranges. You can do it in SE11 or in SE24. I generally prefer doing it in SE24.
    Go to Types Tab
    Declare your range type
    TYPES: ty_r_kunnr type range of kna1-kunnr.
    2) Use this type to declare your method's parameters:
    IR_KUNNR TYPE TY_R_KUNNR
    3) When calling the method you can do like:
    CALL METHOD O_REF->GET_dATA
      EXPORTING
        IR_KUNNR = S_KUNNR[].
    Regards,
    Naimesh Patel

  • Declared Web Dynpro method's javadoc not updating

    Hello all,
    I declared a method in a custom controller, and changed the Javadoc to something more meaningful than the usual "declared method.". Now I'm trying to call this method from another controller. That in itself works fine, but when using NWDS' auto-complete feature, I still see the old, initial Javadoc.
    I've tried building the project, reloading+rebuilding it, I even tried restarting the entire NWDS, all without success. Am I missing something? What does it take to get the NWDS to use the updated javadoc?
    Thanks in advance,
    Kars.

    Hi,
    if i am not wrong the JDK need to support the new java doc, mean to say are you using right jdk version for that. Coz javadoc.exe need to support.
    plz give a try to this setting:-
    Go to window-> preferences->jav->javadoc->javadoc command in that set the path for the javadoc.exe.
    Hope this may help you.
    Regards,
    Deepak

Maybe you are looking for

  • Is there an easy way to reimport all songs in my itunes folder?

    This may sound like a weird question but here goes... When I bring up my iTunes I have 8731 files (mostly music) that come to about 41.33G's but when I right click on my iTunes Music folder and select properties there are 8809 files and a total of 48

  • How to restore table data to one week old status

    I have a table vu_med_reimburse and  some of columns are VMR_MM, VMR_YYYY, VMR_ACTUAL_AMT the insert process to this table is done through another program but update of three columns are done throgh another program, by mistake all the values of above

  • How to change the quota of a workspace on OCS10g?

    Hi, How to change the quota of a workspace on OCS10g? I can't find the site administrator page or workspace administrator page to change the quota of workspaces? Regards, Kitae Message was edited by: kitaelee

  • Problem with servlet call within servlet

    I have already a servlet that generates a jpeg images that works fine. a second servlet generates an pdf document via the iText library and works also fine. the problem or question is how to call the first servlet to insert an image into the generate

  • Oracle OVM 3.1 Manager Server Discovery WARNING Message.

    I am getting this warning trying to run [ Discover Servers ] in my OVM Manager. Can someone help figure out what is that I am missing here. [root@ovmserver1 log]# [root@ovmserver1 log]# cat ovs-agent.log [2011-11-23 09:05:09 18587] DEBUG (OVSCommons: