This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

local variable  RSS feed

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


 
Matthew Brown
Bartender
Posts: 4568
9
  • 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
Sheriff
Posts: 23275
125
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
Boost this thread!