<p><font face="맑은 고딕" size="2"><span style="line-height:12px;">public class Circle {</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span>private double radius;</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span>public Circle(){</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> System.out.println("Circle()");</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> }</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> public Circle(double radius) {</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> this();</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> this.radius = radius;</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> System.out.println("Circle(double radius)" + this.radius);</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> }</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">}</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span>class SubCircle extends Circle</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span>{</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span>private Circle inner = new Circle(1); </span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> public SubCircle()<span class="Apple-tab-span" style="white-space:pre;"> </span>{</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> super(5);<span class="Apple-tab-span" style="white-space:pre;"> </span></span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> System.out.println( "SubCircle()" );</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> }</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> public static void main(String args[]) {</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> new SubCircle();</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> }</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><span class="Apple-tab-span" style="white-space:pre;"> </span>}</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">위 코드를 출력하면</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle()</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle(double radius)5.0</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle()</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle(double radius)1.0</span></font></p> <p></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">SubCircle()</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><br></span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">이런 출력결과가 나오는데 이해가 잘 안되네요. 처음 메인에서 SubCircle 객체를 생성하면 </span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">1. super(5)===> Circle(5) 가 실행되고</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">2. Circle(5) 생성자 안에서 Circle() 생성자 실행 ==> "Circle()" 출력</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">3. 다음 "CIrcle(5.0)" 출력</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">다음에 "SubCircle()"가 출력 되야하는것이 아닌가요? </span></font><span style="font-family:'맑은 고딕';font-size:small;line-height:12px;">System.out.println( "SubCircle()" ); 이 라인이 SubCircle() 생성자 안에 같이 있으니까 </span></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle()</span></font></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle(double radius)5.0</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">SubCircle()</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><br></span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">이런식으로 출려되야 되는것이 아닌가요?</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">왜 private Circle inner = new Circle(1); 라인이 먼저 실행되고 서브서클이 제일 나중에 출력되나요?</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">만약 SubCircle 객체가 생성될때 객체안 프라이비트 변수 초기화가 제일 먼저 실행된다고 치면 </span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;"><br></span></font></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle()</span></font></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle(double radius)1.0</span></font></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle()</span></font></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">Circle(double radius)5.0</span></font></p> <p style="line-height:14.3999996185303px;"></p> <p style="line-height:14.3999996185303px;"><font face="맑은 고딕" size="2"><span style="line-height:12px;">SubCircle()</span></font></p> <p><font face="맑은 고딕" size="2"><span style="line-height:12px;">이렇게 출려되야 하는것 아닌가요?</span></font></p>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.