Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2008, 11:57 AM
Registered User
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Keyword final

in his book: Ivor Horton's Beginning Java 2 JDK 5 edition on page 227 he uses in a constructor the word final:

Point(final Point oldPoint) {
x=oldPoint.x
y=oldPoint.y
}

what does the keyword final does here? if you don't use it the results remain the same. Can someone give me an example where it does matter that you use the keyword final in the argument of a constructor?

thnx,

Greets,
Leville

 
Old January 22nd, 2008, 04:11 PM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

Never used keyword "Final" when passing in as a parameter to a method, but an educated guess is that the parameter, in this case a value type, is immutable (can't be changed)

the Point you're passing in is a reference type, so within the function, you couldn't do something like:

oldPoint = new Point(10,20)

Because this would violate the final clause

Again, just an educated guess

thanks
 
Old March 6th, 2008, 04:56 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

I remember reading somewhere about using Final as an access modifier and agree with the above posting. It can also be used to prevent the overriding of methods in sub classes if the method in the superclass is defined as Final.

Hope this helps
Mark

 
Old August 16th, 2008, 01:13 PM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ch.venki Send a message via MSN to ch.venki Send a message via Yahoo to ch.venki
Default

hi

In three ways we use keyword final.
1) If any word declared as final means its value cant change.
2) If any method declared as final then the method we cant override in the base class.
3) If any class is declared as final then it cant participate in inheritence. It means we cant create base class using it.

i hope it will helps u,
ch.venki
 
Old September 19th, 2008, 09:35 PM
yulin11
Guest
 
Posts: n/a
Default

yeah. It means that the value of the parameter can't be changed.So if you have some value which don't want to be changed. You'd better do it like this.

everyone can go far!www.codeuu.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML final output sanek55555 XSLT 8 November 2nd, 2006 04:12 AM
Blank Final Consigliori Java Basics 1 September 27th, 2006 09:25 AM
Blank Final Consigliori Java GUI 0 September 7th, 2006 01:57 PM
Difference between static and final ravikumar681 J2EE 2 June 24th, 2004 07:54 AM
Ch. 2: Cannot inherit from final class joew098 JSP Basics 0 September 17th, 2003 04:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.