Finding out the object of the class

This section illustrates how to
retrieve an object name that reflects the package name by using the
object.getClass() method. Here is an example that provides the
proper usage of the object.getClass() method in more detail.
Create a class "Fobject" with an object Checkbox. Now retrieve
an object name that reflects the package name by
using the object.getClass() method.
Here is the code of the Example :
Fobject.java:
import java.lang.reflect.*;
import java.awt.*;
public lass Fobject{
public static void main(String[] args) {
Checkbox bos = new Checkbox();
printName(bos);
}
static void printName(Object objct) {
Class cls = objct.getClass();
String strng = cls.getName();
System.out.println(strng);
}
}
|
Here is the output of the Example :
C:\roseindia>javac Fobject.java
C:\roseindia>java Fobject
java.awt.Checkbox
|
Download this Example:

|
Current Comments
0 comments so far (post your own) View All Comments Latest 10 Comments: