I have tried to execute the given code given below:
public class XXX
{
public static void main(String[] args)
{System.out.println(new XXX().class);
}
}
But the code shows an error during compilation:
/XXX.java:4: error: <identifier> expected
{System.out.println(new XXX().class);
^
/XXX.java:4: error: ';' expected
{System.out.println(new XXX().class);
^
2 errors
But when I compile the following code:
public class XXX
{
public static void main(String[] args)
{System.out.println(XXX.class);
}
}
it works fine,I mean it prints the output as given below
class XXX
Does this mean that the ".class" operation( I don't know what to call it) in java is only meant for a class and not its instances ?