*
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
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: 4371
    
    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: 18757
    
  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)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: local variable