File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assignment operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assignment operator" Watch "assignment operator" New topic
Author

assignment operator

jaysingh solanki
Greenhorn

Joined: Nov 11, 2003
Posts: 14
code:
class Test
{
int i=4;
i+=5;//line 1
public Test()
{
System.out.println(i);
}
public static void main(String arg[])
{
Test t=new Test();

}
}
My question is why line one gives compile time error
identifier exp.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
"i" is an instance variable (since you don't see the keyword static anywhere).
Consequently, trying to initialize it at the static (class) level will result in an error. If you are trying to make "i" a class-level variable, use the static keyword and place their initiailization in a static { ... } block. Otherwise, "i" is an instance variables and need to be initialized in a constructor, not at Line 1 as it is now.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assignment operator
 
Similar Threads
Static....
Thread problem
about supper() and this(..)
method invocation
instanceof Doubt again??