Results 1 to 8 of 8
  1. #1
    WooHoo88 Guest

    Default What is a final keyword in java????

    What is a final keyword in java????

  2. #2
    BAT Guest

    Default

    When you declare a class to be final, it can never be subclassed. This is usually done for security or performance reasons.

    public final class Math {
    // ...
    }
    Last edited by BAT; October 9th, 2010 at 04:37 PM.

  3. #3
    hadia Guest

    Default

    Final keyword can be used with class, method or field in java.

  4. #4
    cad4321 Guest

    Default

    When you declare a method to be final, it can never be overridden in subclasses. This is usually done for security or performance reasons, providing additional information to the JIT compiler or HotSpot. One word of caution -- making methods final restrict later design decisions.

  5. #5
    cad4321 Guest

    Default

    The final modifier was introduced for local variables in Java v1.1. As with using final on fields, its use means that the local variable may not be modifed inside that method. This means that the compiler can catch any invalid modifications made in the method and it may be able to make better optimizations since it knows more about the intentions of the code.

    Note that with final local variables you may defer initialization as long as the variable is definitely assigned before any use and that it assigned a value exactly once.

    So, use the final modifier on local variables when you want to make it clear that the variable is only assigned once during the method and never changed thereafter.

    Note that another use for final local variables is in the case where an inner class needs to access "variables" of the enclosing class.

    Remember that, in Java, inner classes are really just syntactic sugar. The inner classes don't have any magical way to access the enclosing classes that aren't explicit. Check out the JLS for the details.

  6. #6
    AutoLady Guest

    Default

    Fields and methods can also be declared final. A final method cannot be overridden in a subclass. A final field is like a constant: once it has been given a value, it cannot be assigned to again.

    Java Code
    private static final int MAXATTEMPTS = 10;

  7. #7
    JIM Guest

    Default

    A final is a keyword in java. If final keyword is applied to a variable, then the variable will become a constant. If it applied to method, sub classes cannot override the method. If final keyword is applied to a class we cannot extend from that class.

  8. #8
    marcoterz Guest

    Default

    You can find lots of info on the final keyword and its different uses here https://sites.google.com/site/javadvanced/final-keyword

Similar Threads

  1. keyword createobject
    By EXT25 in forum Automation Applications & Software
    Replies: 3
    Last Post: October 23rd, 2010, 02:15 PM
  2. Difference between final, finally and finalize()
    By govin in forum Programming Languages
    Replies: 7
    Last Post: October 15th, 2010, 01:45 PM
  3. what is the difference between final and constant?
    By TomLee in forum Programming Languages
    Replies: 4
    Last Post: October 10th, 2010, 05:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •