I had a question regarding the following assignment.
Class cls = Item.class;
Can anybody tell me where is class for Item defined as I have not defined the 'class' for my Item class. I checked JLS for Object but did not find it there.
It is possible to do better than find the class file for you. Assuming that your .java file compiles then it should be possible to train you to find it yourself.
If your program compiles then post the (1) package statement at the top of the file that contains the Item.class usage, (2) the import statements at the top of the same file, (3) your javac command line (especially any -classpath argument). If your javac command line contains no -classpath argument then post (3') the CLASSPATH setting for your environment.
This is taken directly from the documentation of the Class class.
public final class Class<T> extends Object implements Serializable, GenericDeclaration, Type, AnnotatedElement
Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.
Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.
...It is also possible to get the Class object for a named type (or for void) using a class literal (JLS Section 15.8.2). For example:
System.out.println("The name of class Foo is: "+Foo.class.getName());
Originally posted by Deepak Chandrashekar Avanna: ... Can anybody tell me where is class for Item defined as I have not defined the 'class' for my Item class...
Welcome to JavaRanch!
I'm not entirely clear on what you're asking: Are you saying that you can't find a definition for Item.class? Or are you asking about the Class.class? It looks like both interpretations have been addressed above.
I am not clear about your post. To put my question in better way, I just wanted to know where is the "class" in Item.class defined. Is it inherited from Object?