Output Package name and Class name
How we get the output as "class java.packagename.classname" of appropriate class we used in the program
for example,
Class check
{
public static void main(String args[])
{
int x= new Integer(10);
----------------------------
-----------------------------.
}
}
Some thing code should be written, then we have to get output as
class java.lang.Integer
to get output as in the above format, what is the code have to be written in the blanks, i.e., only there is just 2 lines of code.....
Can you please explain ?
Re: Output Package name and Class name
Hi varanasisaikarthik,
I think actual code on main method would be
Integer i=new Integer(10);
-----------------------------
-------------------------------
If it is int i=new Integer(10); it will give type mismatch error
And to get the type of object,like in this example: java.lang.Integer
We have to use the following code:
---------- Class c=i.getClass();
----------- System.out.println("class"+c.getName());
These are the two lines that would satisfy your need.
If you have any issues please reply.
Thanks & Regards,
Ch.suresh