• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local variable

 
Ritesh raushan
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why this gives error...


 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because Java doesn't support default parameter values. Which means your line 4 is invalid syntax.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic