Forums Register Login

What will make better efficient?

+Pie Number of slices to send: Send
Hello,
If I write the following class in two style:
Style A:
*************


Style B
**************


Which is better way of decalring xx object and why? or this is soley depend upon the requirement?
regards,
arun
[ April 04, 2002: Message edited by: Cindy Glass ]
+Pie Number of slices to send: Send
It's important to remember that initialization of instance variables is not the same as executing a constructor. In the case you gave, the results would probably be the same either way. However, consider what would happen if you had multiple constructors:

In such a case, it would probably be better to initialize the member xx outside of the constructors because, otherwise, you're simply creating extra code.
Corey
+Pie Number of slices to send: Send
Just as a side-note, there a many intricacies to initializing a class. Take a look at the JLS, §12.4 Initialization of Classes and Interfaces or do a search in the Programmer Certification Forum to get all sorts of juicy details.
Hope that helps,
Corey
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 616 times.
Similar Threads
null pointer exception
Runtime vs Compile time
Syntax for mapping a var to a method
Using instance variables
why equal
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:32:42.