What's the difference between initializing a class field at the point of declaration and initializing it in the constructor, beside syntax? Is one of these alternatives preferable?
class myClass {
Object o;
public myClass() {
o = new Object();
}
}
VS
class myClass {
Object o = new Object();
public myClass() {
}
}
Question
Andre S. Veteran
What's the difference between initializing a class field at the point of declaration and initializing it in the constructor, beside syntax? Is one of these alternatives preferable?
class myClass { Object o; public myClass() { o = new Object(); } }VS
class myClass { Object o = new Object(); public myClass() { } }Thanks.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts