Web Design and Web Development Forum

  1. #1
    Join Date
    Aug 2005
    Posts
    31
    Rep Power
    0
  2. priyak is on a distinguished road
  3. println

    we use System.out.println to display a string.such as " hello world" but we may also pass
    an object as the argument of the println method and as a result a diferent message describing the object is printed.

    my question is how does it distinguish between the string object i want to print intact and any other object i pass (such as an exception).
    Reply With Quote Reply With Quote
  4. #2
    hot_cakes's Avatar
    Join Date
    Aug 2005
    Location
    Bristol, UK
    Age
    30
    Posts
    2,913
    Rep Power
    9
  5. hot_cakes will become famous soon enough
  6. Re: println

    PrintStream.println has numerous overloads. One of them takes an Object argument. To turn this argument in to a string String.valueOf(obj) is used.

    Have a look at the Java API docs for more information (lookup PrintStream.println -- System.out is a PrintStream object).

    Edd
    Visit me at: mr-edd.co.uk
    Languages: Python | Lua
    Compilers: MinGW | MSVC++9
    Libraries: Boost | gtkmm
    Reference: Dinkumware | a.c.l.l.c-c++ FAQ
    Reply With Quote Reply With Quote
  7. #3
    byteCode's Avatar
    Join Date
    Apr 2005
    Location
    India
    Age
    21
    Posts
    91
    Rep Power
    8
  8. byteCode is on a distinguished road
  9. Re: println

    To allow special printing for a custom object eg. You create a Circle class, say, and u want the radius and coordinates of the center printed out when u do a println on it. then overload the toString method from class Object(auto superclass of all classes) and add a 'return "r = "+radius+"c = (" + x + ", " + y + ")"' to it

    Nikhil
    KodeClutz | 22bits

    Microsoft is not the Answer, Microsoft is the Question, NO is the Answer.
    Reply With Quote Reply With Quote