dcsimg
printing the class name
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chintu_Kalidindi
Posted On:   Thursday, July 1, 2004 06:52 AM

Is there a way to get the name of the class within the class itself?eg:if working on HelloWorld.java ,



public class HelloWorld{


public static void main(str[] args){
sysmtem.out.println( class.getClassName() );
}


}


Is there a way to get the name of the class?similar to the dummy method...getClassName();

Re: printing the class name

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, July 1, 2004 10:17 AM

If the method is not static, you can do "this.getClass().getName()". But in a static method like "main", I am not sure, if you don't already have the name in the first place.

Re: printing the class name

Posted By:   Sean_Owen  
Posted On:   Thursday, July 1, 2004 07:32 AM

Sure, the javadoc for java.lang.Class has examples showing this very thing. You need to use the getName() method.
About | Sitemap | Contact