aspose file tools*
The moose likes Java in General and the fly likes Syntax error on token <variableName>, VariableDeclaratorId expected after this token Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Syntax error on token <variableName>, VariableDeclaratorId expected after this token" Watch "Syntax error on token <variableName>, VariableDeclaratorId expected after this token" New topic
Author

Syntax error on token <variableName>, VariableDeclaratorId expected after this token

Avanti Deshpande
Greenhorn

Joined: Jul 14, 2011
Posts: 2
Following is the Code :-

This program runs perfectly fine. But if I remove curly braces from the statement {s = "C++";} from XClass or from {s = "C#";} from YClass. It gives me an compilation error that "Syntax error on token s , VariableDeclaratorId expected after this token".
1. Can any one please tell me what is the importance of curly braces in these statement ?
2. If I run YClass it gives me the value of super.s as "C#". My question is why not "C++". Since in XClass the reinitialization happened for this veriable. What I need to do to get value as "C++" ?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

1. It is called an initialization block. It runs when an Object of that class is created.
2. The initialization block in YClass sets the value of s to "C#". Therefore the old value cannot be retrieved.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And welcome to the JavaRanch!
Rushikesh Wagh
Ranch Hand

Joined: Jun 18, 2005
Posts: 58
1. {} is required cause you are assigning value. You are not declaring it.
2. As you have intiated the object using XInterface ob = new YClass(); this statement. JVM will execute curley braces and assign value to it as C#. hence answer is C#.

Regards,
Rushi


Best Regards,
Rushikesh Wagh
SCJP 1.4 (2005)
SCJP 1.6 (2010)
Avanti Deshpande
Greenhorn

Joined: Jul 14, 2011
Posts: 2
Thanks Wouter and Rushikesh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Syntax error on token <variableName>, VariableDeclaratorId expected after this token
 
Similar Threads
Help
Doubt in ExamLab
Exam Lab Question
super reference nor referring to the super class Examlab Test no 2 question 2
use of super -Examlab Question