Two Laptop Bag*
The moose likes Beginning Java and the fly likes non-overridable methods in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non-overridable methods in JAVA" Watch "non-overridable methods in JAVA" New topic
Author

non-overridable methods in JAVA

Ankur Pandya
Greenhorn

Joined: May 28, 2009
Posts: 3
Hi, Anyone can tell me name of some methods which can not be overriden in JAVA..?
Like Static, Final etc....
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
If you are looking for actual methods, I'm sure there are TONS out there. Therefore, I will direct you to the Java 6 documentaiton here.

If you start digging through classes in there I'm sure you will find many examples.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Rajkishore Pujari
Ranch Hand

Joined: Sep 03, 2005
Posts: 46
There are so many. Example: java.lang.Math class is a final class. so you can not extend it and all the methods in it are final.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The quickest way to get a complete list would be to grab a byte-code analyzer and just go through all the jars and look for signatures. I'm not sure why anybody would need a list like this, but that'd be how I'd get it.
Matthew Cox
Greenhorn

Joined: May 25, 2009
Posts: 29
Ankur Pandya wrote:Hi, Anyone can tell me name of some methods which can not be overriden in JAVA..?
Like Static, Final etc....



Based on your wording, I think what you are trying to ask is, "What type of modifiers can prevent methods from being overriden?"

If my assumption is correct then the answer would be marking something as final (a field modifier).

There are drawbacks to marking anything as final method or variable. So my recommendation is to consider the purpose of the class and the need to mark something as final.


If this is not the case then the resources that the other posters have given would be more than sufficient
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Matthew Cox wrote:There are drawbacks to marking anything as final method or variable.


What are all the drawbacks?
Matthew Cox
Greenhorn

Joined: May 25, 2009
Posts: 29
seetharaman venkatasamy wrote:
Matthew Cox wrote:There are drawbacks to marking anything as final method or variable.


What are all the drawbacks?


variables and methods marked as final have the drawback of the following:

1. Scale of use - Items that utilize final are more commonly data structures or prohibitive supertypes as they cannot be modified (method or object) and can only be assigned a value or implementation (respectively) once.

2. Flexibility - Future builds of your code could have dependencies upon objects, variables, and methods that are marked as final, but conflict with newer code requirements.

3. Incompatibility with Inheritance (as in the item cannot be extended or enhanced in any form)
-Although, I do understand and admit that in most cases, the use of final would be just for this purpose, to prevent modification

I want to make a clear statement though. I only mentioned the "drawbacks" in relation to the possibility of using final haphazardly. If this modifier is used correctly, then drawbacks will not be an issue. But simply using this modifier to restrict access without regards to future modification or needs would be careless at best.

Since the question was semi-vague to begin with (no offense meant to the original poster), I merely wanted to give warning if this was the case for him.

P.s

I bet there are more, but since I possess only so much knowledge =P that is all I can list for now.
 
Consider Paul's rocket mass heater.
 
subject: non-overridable methods in JAVA