J
Joan
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
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