Results 1 to 2 of 2

Thread: Output Package name and Class name

  1. #1

    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 ?


  2. #2
    Banned
    Join Date
    Jan 2008
    Answers
    25

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact