Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) They have to be <code>static</code>, in order to not be overridden in some sub class. I hope you understand.</p> <p><strong><code>&lt;Addendum&gt;</code></strong></p> <p>Shrini, from your comment, it seems that there is a need to explain the things to avoid some misconceptions. First of all, know on thing that <code>static</code> methods can not be overridden. Overriding is exclusive in objects, and it is there to facilitate polymorphism. Whereas static methods belongs to the class. Found a couple of good resources to support my argument and for you to understand that static methods can not be overridden.</p> <ul> <li><a href="http://geekexplains.blogspot.com/2008/06/can-you-override-static-methods-in-java.html" rel="nofollow noreferrer">Can you override static methods in Java</a></li> <li><a href="http://forums.sun.com/thread.jspa?threadID=597378" rel="nofollow noreferrer">Why static methods can't be abstract</a></li> </ul> <p>Now for your second retort, you are right in saying that they have package level access and can't be overridden in subclasses outside the package. But I don't know why are you neglecting the case where subclass/es exist in the same package. Its a valid case, IMO. In fact, it would be absurd to name a method like <code>access$000()</code> or something like that, in a real work. But don't underestimate the chance of accidental overriding. There can be a case where the subclass of <code>Outer</code>, say <code>SubOuter</code>, has an inner class of itself too. I didn't try to <code>javap</code> that case myself, just guessing.</p> <p><strong><code>&lt;/Addendum&gt;</code></strong></p> <p>2) Even if you think it will not get modified, technically there is a possibility as cletus pointed out already, use of <code>final</code> can provide easy optimizations by the compiler.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload