Home Java Reflect Finding out the object of the class
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Finding out the object of the class

Advertisement
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.

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:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Related Tutorials

Ask Questions?    Discuss: Finding out the object of the class  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com