wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes What will make better efficient? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What will make better efficient?" Watch "What will make better efficient?" New topic
Author

What will make better efficient?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
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 ]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: What will make better efficient?
 
Similar Threads
why equal
Syntax for mapping a var to a method
null pointer exception
Using instance variables
Runtime vs Compile time