Win a copy of Rust Web Development this week in the Other Languages forum!

Will Kasper

Greenhorn
+ Follow
since Nov 25, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Will Kasper

Seetharaman Venkatasamy wrote:
If you explicitly assigned value inside one constructor and forget to do in another then constructor dont do that for you which result some error.


I like this. It sounds like a good reason to stick to situation 1.

I was just wondering if one style was more *elegant* than the other. I try to follow best practices whenever possible, but sometimes it's not clear what those best practices are. I've seen both styles used in examples of code so I figured I'd try and get to the bottom of which one to use. Thank you all very much!
9 years ago

Seetharaman Venkatasamy wrote:Good question and Welcome to JavaRanch Will Kasper


Thank you, I'm glad to be here. I've lurked for a while but I decided it was time to sign up and become part of the community. I appreciate all the great answers.
9 years ago
Hello all,

I was wondering if there is a difference between these two situations, and if so, which one should I use.

Situation 1:


Situation 2:


I assume that they both yield the same end result, but is one better to use than the other? Does situation 1 initialize the values at compile time while situation 2 initializes the values at run time? Or am I just splitting hairs here? Thank you so much, I look forward to your answers!
-Will
9 years ago