What's the difference between a default constructor and just initializing an object's fields directly?
What reasons are there to prefer one of the following examples over the other?
Example 1
public class Foo
{
private int x = 5;
private String[] y = new String[10];
}
Example 2
public class Foo
{
private int x;
private String[] y;
public Foo()
{
x = 5;
y = new String[10];
}
}
Your Answer
0 answers
Hot tools Tags
Hot Questions
Copy array by value
2026-01-02 14:43:10
Go variables being overwritten (bug?)
2026-01-02 14:22:47
unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed with ChromeDriver Selenium
2026-01-02 14:01:58
When are C++ macros beneficial? [closed]
2026-01-02 13:43:17
How to make pipes work with Runtime.exec()?
2026-01-02 13:22:05
Popular tool
vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation
VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library
PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment
VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library
SublimeText3 Chinese version
Chinese version, very easy to use
Hot Topics
Douyin level price list 1-75
20416
7
20416
7
wifi shows no ip assigned
13574
4
13574
4
Hot Article
What is the 'basis' of a currency contract? What impact does it have on perpetual contract prices?
2025-12-26
By DDD
How to set up price alerts so you don't miss key entry points?
2026-01-01
By DDD
Tutorial on existence check of nested array values in PHP multidimensional array
2025-12-28
By DDD
How to draw dotted lines in PS How to draw various dotted lines in PS
2025-12-28
By DDD






