This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes local variable 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 "local variable" Watch "local variable" New topic
Author

local variable

Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100
why this gives error...


Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

Because Java doesn't support default parameter values. Which means your line 4 is invalid syntax.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

In the future, please TellTheDetails(⇐click). Copy/paste the exact, complete error message.

Here, however, it's easy to see one problem right off the bat.


Java does not allow you to provide default values for method arguments. You should go back and review the method declaration section of your text or tutorial, such as: http://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

As a side discussion, this is a cool feature of C++ that I kinda miss in Java -- especially when you want to add a new parameter, but want to remain backward compatible with old code. With Java, I would simply add the parameter, and then create an overloaded method with the old parameter set that calls the new parameter set with the appropriate (default) parameters.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: local variable