• Post Reply Bookmark Topic Watch Topic
  • New Topic

Illegal modifier for parameter y, only final is permitted  RSS feed

 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting error while declaring fields inside the main method......please tell me what is wrong in this

error:-
Illegal modifier for parameter y, only final is permitted


IfClause.java :-



Screenshot is attached also for your reference
Filename: error.bmp
Description: Error
File size: 648 Kbytes
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot set visibility scopes (private,...) to local variables.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot set visibility scopes (private,...) to local variables.
as said by Christophe Verré
but why, may i know the reason behind this ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it make sense ? What benefits would you get by making it private ? Private to whom ? The Local variables scope is already well defined : within the scope of the method it lives in.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static also doesn't apply to local variables, unlike in C / C++.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Static also doesn't apply to local variables, unlike in C / C++.


I actually like this feature in C/C++. Granted it is not really a local variable. It's more like a global variable that is private to the function.... or maybe it's more like a local variable, whose scope doesn't end when the function returns.

Henry
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it make sense ? What benefits would you get by making it private ? Private to whom ? The Local variables scope is already well defined : within the scope of the method it lives in.
as said by Christophe Verré

Thanks fro your response, i got it what you are saying.

 
Stephan van Hulst
Saloon Keeper
Posts: 7961
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. Local variables are local. Meaning you can't access them through a global scope.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i want to know that if there is method say abc() which is public for instance like :-



[b]

From another class, i have created the object of this class and accessed this abc() method...success..
But why i'm not able to access the field x inside this method ?
I can access any field i.e. global variables only but why can't for local variables ? how can i put values in this local field through the object created ?
please tell me this briefly...
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod Vijay wrote:Now i want to know that if there is method say abc() which is public for instance like :-





From another class, i have created the object of this class and accessed this abc() method...success..
But why i'm not able to access the field x inside this method ?

To put it in a simple way: because when the method call returns, the variable no longer exists.

Vinod Vijay wrote:I can access any field i.e. global variables only but why can't for local variables ? how can i put values in this local field through the object created ?
please tell me this briefly...

A local variable is NOT a field. Have you ever heard of parameters?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!