Results 1 to 4 of 4
  1. #1
    abhinav435 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Problem about uesr defined class: want explanation

    Hello friend's i wrote a program

    class Abc
    {
    public static void main(String args[])
    {
    Abc a=new Abc();
    System.out.println(a);
    }
    }

    and got the output: Abc@17182c1

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,648
    Blog Entries
    7
    Rep Power
    21

    Default Re: Problem about uesr defined class: want explanation

    The print( ... ) method callls the toString() method on an object when it has to print that object. The class Abc doesn't overrride the toString() method so it inherits that method from the Object class. What you saw is the result of the toString() method applied to an Abc object. Read the API documentation for details of its toString() method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    abhinav435 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Problem about uesr defined class: want explanation

    Thnk u bro...............

  4. #4
    abhinav435 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Problem about uesr defined class: want explanation

    toString

    public String toString()

    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

    The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

    getClass().getName() + '@' + Integer.toHexString(hashCode())


    Returns:
    a string representation of the object.

Similar Threads

  1. Replies: 2
    Last Post: 06-16-2011, 09:39 AM
  2. Problem with user defined class in ArrayList
    By anders73 in forum New To Java
    Replies: 4
    Last Post: 04-26-2011, 03:59 PM
  3. Replies: 6
    Last Post: 01-26-2011, 07:49 PM
  4. How to call defined java class in Jsp
    By asheeshiit in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-04-2009, 04:21 AM
  5. Class explanation
    By mcal in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 06:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •