Confusion about how to access methods?

Discussion in 'Java' started by Joan, Jan 26, 2004.

  1. Joan

    Joan Guest

    I am beginner in Java programming. I have a question about

    I know that you can't reference a method with a variable that is not
    initialized with a newly constructed object or an existing object. So
    the following would have a compile-time error:

    (reference the book Core Java 2 Volumn I - Fundamentals by Horstmann &
    Cornell page 121-122)
    Date deadline;
    s = deadline.toString();

    Instead, the following is right:

    Date deadline = new Date();
    s = deadline.toString();


    My question is: according to this rule, how can code like the
    following also works?

    catch(Exception e) {
    e.printStackTrace();
    }

    So the variable e is not yet initialized. How can it access the method
    printStackTrace()?

    Please kindly advise. Thank you.

    Joan
     
    Joan, Jan 26, 2004
    #1
    1. Advertising

  2. "Joan" <> wrote in message
    news:...
    | I am beginner in Java programming.

    perhaps you will getter better help at..
    news:comp.lang.java.help for the moment.

    | catch(Exception e) {
    | e.printStackTrace();
    | }
    |
    | So the variable e is not yet initialized.

    It most certainly is. The Exception object
    'e' is instantiated by the class or method that
    'throw's the exception object.

    HTH

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
     
    Andrew Thompson, Jan 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TheFerryman

    confusion with abstract methods.

    TheFerryman, Apr 5, 2004, in forum: C++
    Replies:
    3
    Views:
    315
    Rolf Magnus
    Apr 5, 2004
  2. Martin Magnusson
    Replies:
    1
    Views:
    387
    Rob Williscroft
    Nov 23, 2004
  3. Replies:
    3
    Views:
    326
    Lew Pitcher
    Sep 29, 2003
  4. Kenneth McDonald
    Replies:
    5
    Views:
    376
    Kenneth McDonald
    Sep 26, 2008
  5. Adam Wilson
    Replies:
    2
    Views:
    160
    trans
    Feb 20, 2009
Loading...

Share This Page