I am executing the following program.
public class MoreInitializers
{
int noOfdays = 7 * NO_OF_WEEKS;//1
System.out.println("noOfdays : " + this. noOfdays);//2
static int NO_OF_WEEKS = 52;//3
public static void main(
String args[])//4
{
MoreInitializers obj1 = new MoreInitializers();
System.out.println("noOfdays : " + obj1.noOfdays);
System.out.println("NO_OF_WEEKS : " + NO_OF_WEEKS);
}
}
Now at line 2 - I am trying to print the value of "noOfdays" . Basically
I tried giving the variable noOfdays and this.noOfdays in the println statement.
I get this error in either case at the compile time:
D:\Java_prgms\gc\MoreInitializers.java:4: <identifier> expected
System.out.println("noOfdays : " + this. noOfdays);//2
^
1 error
Tool completed with exit code 1
Please explain why this error occurs?
Is it valid to access and print the value of variable noOfdays at line 2? If yes then how cann I access it?
Thanks,
Rekha