📄 tij0055.html
字号:
<html><body>
<table width="100%"><tr>
<td>
<a href="http://www.bruceeckel.com/javabook.html">Bruce Eckel's Thinking in Java</a>
</td>
<td align="right">
<a href="tij_c.html">Contents</a> | <a href="tij0054.html">Prev</a> | <a href="tij0056.html">Next</a>
</td>
</tr></table>
<hr>
<H2 ALIGN=LEFT>
Exercises</H2>
<OL>
<LI><FONT FACE="Carmina Md BT" SIZE=5 COLOR="Black"> </FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Create
a class with a default constructor (one that takes no arguments) that prints a
message. Create an object of this class.
</FONT><LI><FONT FACE="Carmina Md BT" SIZE=5 COLOR="Black"> </FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Add
an overloaded constructor to Exercise 1 that takes a
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>String</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
argument and prints it along with your message.
</FONT><LI><FONT FACE="Carmina Md BT" SIZE=5 COLOR="Black"> </FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Create
an array of object handles of the class you created in Exercise 2, but
don’t actually create objects to assign into the array. When you run the
program, notice whether the initialization messages from the constructor calls
are printed.
</FONT><LI><FONT FACE="Carmina Md BT" SIZE=5 COLOR="Black"> </FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Complete
Exercise 3 by creating objects to attach to the array of handles.
</FONT><LI><FONT FACE="Carmina Md BT" SIZE=5 COLOR="Black"> </FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Experiment
with
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>Garbage.java</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
by running the program using the arguments “before,”
“after” and “none.” Repeat the process and see if you
detect any patterns in the output. Change the code so that
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>System.runFinalization( )
</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">is
called before
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>System.gc( )</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
and observe the results.
</FONT></OL><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Da Vinci Extras" SIZE=39 COLOR="Black">d</FONT><a name="Chapter_5"></a><a name="_Toc375545290"></a><a name="_Toc407441449"></a><a name="_Toc408018493"></a><P></DIV>
<div align="right">
<a href="tij_c.html">Contents</a> | <a href="tij0054.html">Prev</a> | <a href="tij0056.html">Next</a>
</div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -