|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--java.lang.Class
Class objects contain runtime representations of classes. Every object in the system is an instance of some Class, and for each Class there is one of these descriptor objects. A Class descriptor is not modifiable at runtime.
The following example uses a Class object to print the Class name of an object:
void printClassName(Object obj) {
System.out.println("The class of " + obj +
" is " + obj.getClass().getName());
}
| Method Summary | |
static Class |
forName(String className)
Returns the runtime Class descriptor for the specified Class. |
ClassLoader |
getClassLoader()
Returns the Class loader of this Class. |
Class[] |
getInterfaces()
Returns the interfaces of this Class. |
String |
getName()
Returns the name of this Class. |
Class |
getSuperclass()
Returns the superclass of this Class. |
boolean |
isInterface()
Returns a boolean indicating whether or not this Class is an interface. |
Object |
newInstance()
Creates a new instance of this Class. |
String |
toString()
Returns the name of this class or interface. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
public static Class forName(String className)
throws ClassNotFoundException
Class t = Class.forName("java.lang.Thread")
className - the fully qualified name of the desired Class
ClassNotFoundException - If the Class could not be found.
public Object newInstance()
throws InstantiationException,
IllegalAccessException
InstantiationException - If you try to instantiate
an abstract class or an interface, or if
the instantiation fails for some other reason.
IllegalAccessException - If the class or initializer
is not accessible.public String getName()
public Class getSuperclass()
public Class[] getInterfaces()
public ClassLoader getClassLoader()
ClassLoaderpublic boolean isInterface()
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||