SCJP題庫第065題


Replace two of the Modifiers that appear in the Single class to make the code compile. Note: Three modifiers will not be used and four modifiers in the code will remain unchanged.

Ans:

解說:
getInstance中喚用create方法,因為getInstancestatic,要直接使用create方法(不透過物件)的條件create方法必須為static
因此,把protected換成static
題目的條件:三個存取修飾子將不會被用到,並且,程式碼中四個修飾子保持不變
我們已經將protected換成static,程式碼中少掉一個修飾子,加上程式碼中四個修飾子保持不,少了一個protected
四個修飾子中要找一個換上protected,這支程式,可以換掉的只有private,依封裝的原則,資料成員應為private,所以能改的就是Single這個建構子。

Comments

Popular posts from this blog

Android+Google Map API v3 Geocoding(地址轉經緯度度