class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
Run Code Online (Sandbox Code Playgroud)
由于我只在构造函数中初始化两个变量(displayText和state),其余两个变量(meaningfulText以及url具有该值的变量null)是否需要内存空间来存储null值.
Q1.我认为他们需要空间.如果他们愿意,那么一个int值在内存中占用多少内存(比如displayText需要4个字节).
Q2.字符串在内存中占用多少空间.我想这将取决于字符串的长度.那么一个字符串需要多长的空间?
java ×1