File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting error while declaring a String variable in main method

 
Vishnu Sharma
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting an error when i am declaring a String variable as static. The following error is coming:

Overridden.java:21: illegal start of expression
static String output=a1.getdetails();
^


As per my understanding in static method all variables declared must be static. Please correct if i am wrong & answer this error cause also.
 
Vidyakar Sharma
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishnu,

You are declaring a static variable within a static method.
 
Ajay Pinnaka
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All variables inside a method are final variables and cannot be static,private,public or protected.
 
Vidyakar Sharma
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajay,
It's not like that. All variables declared within a method use modifiers of that method.
 
Ajay Pinnaka
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i'm not clear on your reply.Can you please justify with an example.Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only modifier a local variable can have is final. Nothing else.
 
Vidyakar Sharma
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajay,

Rob has already answered.
 
Vishnu Sharma
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:The only modifier a local variable can have is final. Nothing else.


ohk.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Rob has given the correct answer. Variables inside a method (local variables) may be marked "final". Ajay Pinnaka said they are all final, which is very confusing.
 
Ajay Pinnaka
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am so sorry, if i really confused you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apology accepted.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passed in method parameters can be marked as 'final' too.
Jim ... ...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic