S. Vijay wrote:
When I run this code the output is coming as 1,2 which is okay but my question is in this code the d Dimension object is created only in the initialize method and also it is not static whereas in display method how it gets the reference and it prints the values of x and y. It must give NullPointerException right??? As mentioned in Kathy Sierra when we create a new object with a new keyword inside a method then that reference wont be available in other methods.
Does Dimension class objects works differently here ???
Can anyone help me whats going on here?
Thanks
Vijay
hi vijay,
first understand the concepts clearly.........
i assume you have just started learning
java... right?
Dimension-d is not a local variable....it is an member of the class and can be called in any instance method...
as you said Dimension object was created within initialize method only, but its reference is visible to all instance methods as it is a member of prog8 class...