<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-TW">
		<id>https://fgchen.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_178</id>
		<title>SCJP 1.6版考題 178 - 修訂歷史</title>
		<link rel="self" type="application/atom+xml" href="https://fgchen.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_178"/>
		<link rel="alternate" type="text/html" href="https://fgchen.com/wiki/index.php?title=SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_178&amp;action=history"/>
		<updated>2026-05-30T06:46:43Z</updated>
		<subtitle>本 Wiki 上此頁面的修訂歷史</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>https://fgchen.com/wiki/index.php?title=SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_178&amp;diff=1239&amp;oldid=prev</id>
		<title>Ikk：新頁面:  Given:  1. public class Target{  2.   private int i = 0;  3.   public int addOne(){  4.     return ++i;  5.   }  6. }  And:  1. public class Client{  2.   public static void main(Stri...</title>
		<link rel="alternate" type="text/html" href="https://fgchen.com/wiki/index.php?title=SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_178&amp;diff=1239&amp;oldid=prev"/>
				<updated>2013-03-30T01:55:37Z</updated>
		
		<summary type="html">&lt;p&gt;新頁面:  Given:  1. public class Target{  2.   private int i = 0;  3.   public int addOne(){  4.     return ++i;  5.   }  6. }  And:  1. public class Client{  2.   public static void main(Stri...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新頁面&lt;/b&gt;&lt;/p&gt;&lt;div&gt; Given:&lt;br /&gt;
 1. public class Target{&lt;br /&gt;
 2.   private int i = 0;&lt;br /&gt;
 3.   public int addOne(){&lt;br /&gt;
 4.     return ++i;&lt;br /&gt;
 5.   }&lt;br /&gt;
 6. }&lt;br /&gt;
 And:&lt;br /&gt;
 1. public class Client{&lt;br /&gt;
 2.   public static void main(String[] args){&lt;br /&gt;
 3.     System.out.println(new Target().addOne());&lt;br /&gt;
 4.   }&lt;br /&gt;
 5. }&lt;br /&gt;
 &lt;br /&gt;
 Which change can you make to Target without affecting Client?&lt;br /&gt;
  A. Line 4 of class Target can be changed to return i++;&lt;br /&gt;
  B. Line 2 of class Target can be changed to private int i = 1;&lt;br /&gt;
  C. Line 3 of class Target can be changed to private int addOne(){&lt;br /&gt;
  D. Line 2 of class Target can be changed to private Integer i = 0;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:medium;&amp;quot;&amp;gt;解答&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size: medium;&amp;quot;&amp;gt;Ans: D   &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:medium;&amp;quot;&amp;gt; 解說:&lt;br /&gt;
 此題問那一個對Target進行改變而不影響Client？ (Client不用跟著改) &lt;br /&gt;
 &lt;br /&gt;
 A 先i++再回傳值 改成 先回傳值再i++，二種方式的回傳值會差1，Client必須處理這個不同的值&lt;br /&gt;
 B 將i的初值設為1，與原先的初值0不同，Client必須處理這個不同的初值&lt;br /&gt;
 C addOne方法改成私有後，影響Client無法存取該方法&lt;br /&gt;
 D Integer是int的包裝類別，在JDK 1.5之後，Java會對基本資料型態的int與int的包裝類別“自動地“進行基本資料的封箱(auto-boxing)&lt;br /&gt;
   與基本資料的包裝類別拆箱動作(auto-unboxing)，所以換寫成Integer不會造成任何的影響。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/span&amp;gt;	&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
{{SCJP 1.6版考題講解}}&lt;/div&gt;</summary>
		<author><name>Ikk</name></author>	</entry>

	</feed>