It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "local variable" Watch "local variable" New topic

local variable

Ritesh raushan
Ranch Hand

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

Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

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

Joined: Jan 03, 2004
Posts: 6109

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:
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: local variable
It's not a secret anymore!