'분류 전체보기'에 해당되는 글 1035건

  1. 2011.08.25 Taj Mahal ( 타지마할 ) 사진모음 1
  2. 2011.08.24 Java에서 객체의 초기화 순서
  3. 2011.08.17 장어구이
  4. 2011.08.17 우간다에서 온 편지
  5. 2011.08.01 꾸뜹 미나르 유적군 ( Qutab Minar Complex )
  6. 2011.07.28 Taj Mahal
  7. 2011.06.16 [Python] Undo / Redo 구현하기
  8. 2011.06.04 [Android] Image match game
  9. 2011.06.01 석굴암
  10. 2011.05.31 불국사
Travel/2011 Inida2011. 8. 25. 00:08


'Travel > 2011 Inida' 카테고리의 다른 글

Taj Mahal ( 타지마할 ) 사진모음 2  (0) 2011.08.25
꾸뜹 미나르 유적군 ( Qutab Minar Complex )  (0) 2011.08.01
Taj Mahal  (0) 2011.07.28
Posted by chobocho
Coding/Java 삽질기2011. 8. 24. 23:58

자바는 Static block -> Instance block -> 생성자 순으로 초기화가 된다.

먼저 아래와 같은 코드를 실행해 보자.

public class TestClass {
    public static void main (String[] args) {
       System.out.println("---------------------------");
       
       Parent father = new Parent("father");
       
       System.out.println("---------------------------");
    }
}

class Parent {
    public String myName = "Parent";

    static {
        System.out.println ("This is first message of Parent class!");
    }

    public Parent() {
       System.out.println (myName + ": This is third message! I'm a default constructor of Parent class!");
    }

    public Parent(String name) {
        myName = name;
        System.out.println (myName + ": This is third message! I'm a constructor of Parent class!");
    }
    
    {
      System.out.println (myName + ": This is second message!");
    }
}


그럼 하기와 같은 결과를 얻을 수 있다.

---------------------------
This is first message of Parent class!
Parent: This is second message!
father: This is third message! I'm a constructor of Parent class!
---------------------------



 public class TestClass {

    public static void main (String[] args) {
       System.out.println("---------------------------");
       
       Parent father = new Parent("father");
       Parent mother = new Parent("mother");
       
       System.out.println("---------------------------");
    }
}

class Parent {
    public String myName = "Parent";

    static {
        System.out.println ("This is first message of Parent class!");
    }

    public Parent() {
       System.out.println (myName + ": This is third message! I'm a default constructor of Parent class!");
    }

    public Parent(String name) {
        myName = name;
        System.out.println (myName + ": This is third message! I'm a constructor of Parent class!");
    }
    
    {
      System.out.println (myName + ": This is second message!");
    }
}


 위 와 같이 한 줄을 추가하여 실행하면 아래와 같은 결과를 얻을 수 있다.

---------------------------
This is first message of Parent class!
Parent: This is second message!
father: This is third message! I'm a constructor of Parent class!
Parent: This is second message!
mother: This is third message! I'm a constructor of Parent class!
---------------------------


여기서 보면 static { }  으로 둘러 싸인 구문은 객체 생성시 최초 1회만 수행이 되고, 그 뒤에는 수행이 되지 않는 걸 알 수 있다. 그러나 { } 로 둘러싸인 instance block은 객체가 생성 될 때마다 실행 되며 생성자 보다 먼저 생성되는 걸 알 수 있다.

class Child extends Parent {
    public String myName = "Child";

    static {
        System.out.println ("This is first message of Child class!");
    }

    public Child(String name) {
        myName = name;
        System.out.println (myName + ": This is third message! I'm a constructor of Child class!");
    }
    
    {
      System.out.println (this.myName + ": This is second message of Child class!");
    }
  
}



위 와 같이 Parent class를 상속받는 Child 클래스를 만들고, 아래와 같이 객체를 생성해 보자

public class TestClass {
    public static void main (String[] args) {
       System.out.println("---------------------------");
       
         Child son     = new Child("son");
       
       System.out.println("---------------------------");
    }



그럼 하기와 같은 결과가 나온다.

---------------------------
This is first message of Parent class!
This is first message of Child class!
Parent: This is second message!
Parent: This is third message! I'm a default constructor of Parent class!
Child: This is second message of Child class!
son: This is third message! I'm a constructor of Child class!
---------------------------


위 결과를 보면 알 수 있듯이,
부모 클래스의 static block -> 자식 클래스의 static block -> 부모 클래스의 instance block
-> 부모 클래스의 생성자 -> 자식 클래스의 instance block -> 자식클래스의 생성자 순으로 실행 되는 것을 알 수 있다.

마지막으로 아래와 같이 실행을 하면,

public class TestClass {
    public static void main (String[] args) {
       System.out.println("---------------------------");
       
       Parent father = new Parent("father");
      Parent mother = new Parent("mother");
       Child son     = new Child("son");
       
       System.out.println("---------------------------");
    }
}



하기와 같이 실행 된다. 천천히 살펴보면 앞에서 설명한 내용에서 벗어나지 않는다.

---------------------------
This is first message of Parent class!
Parent: This is second message!
father: This is third message! I'm a constructor of Parent class!
Parent: This is second message!
mother: This is third message! I'm a constructor of Parent class!
This is first message of Child class!
Parent: This is second message!
Parent: This is third message! I'm a default constructor of Parent class!
Child: This is second message of Child class!
son: This is third message! I'm a constructor of Child class!
---------------------------





 

'Coding > Java 삽질기' 카테고리의 다른 글

Java 실행 시간 측정 하기  (0) 2011.09.01
[Android] Image match game  (0) 2011.06.04
Android Tetris  (0) 2011.02.02
Posted by chobocho
Travel/Food2011. 8. 17. 00:25


거제도 친구집에 놀러가 먹은 국내산 장어구이!
싱싱한 장어를 바로 손질해 숯불에 구워 먹으니, 이 보다 맛있을 수 없다!

친구야 고맙다!

'Travel > Food' 카테고리의 다른 글

Big crab  (0) 2013.06.08
중국 여행 중 먹은 음식  (2) 2009.12.30
만년교식당  (0) 2009.09.23
Posted by chobocho
My Life/WorldVision2011. 8. 17. 00:04

월드비전으로 후원하는 어린이에게 편지가 왔다. 힘들고 짜증이 날 때, 이런 편지를 받으면 나쁜 기분은 사라지고, 가슴이 따뜻해 진다. 매년 커가는 후원하는 어린이들의 사진을 받아 볼 때마다 뭔가 뿌뜻해 진다. 여유가 있으시면 한 번 동참해 보세요. ^^
 
Posted by chobocho
Travel/2011 Inida2011. 8. 1. 01:47
유네스코 세계문화유산인 꾸뜹 미나르 유적군을 다시 같다왔다.



'Travel > 2011 Inida' 카테고리의 다른 글

Taj Mahal ( 타지마할 ) 사진모음 2  (0) 2011.08.25
Taj Mahal ( 타지마할 ) 사진모음 1  (0) 2011.08.25
Taj Mahal  (0) 2011.07.28
Posted by chobocho
Travel/2011 Inida2011. 7. 28. 04:17


인도를 방문하게 될 기회가 있으면 꼭 가보고 싶었던 따지마할을 다녀 왔습니다.
외국인의 경우 입장료 250Rs와 ADA 500Rs를 합쳐 750Rs를 내야 합니다. 외국인은 표를 사면 매표소 왼편에서 물과 덧신을 무료로 줍니다.
입구에 들어서 따지마할을 바라보면 감동이 밀려 옵니다. 인도 방문시 꼭 추천 드립니다.
Posted by chobocho
Coding/Python 삽질기2011. 6. 16. 01:17
#-*- coding: cp949 -*-
#
# undo/redo 구현 방법
# 1) undo stack를 만든다.
# 2) redo stack를 만든다.
# 3) 새로운 액션을 undo에 넣는다.
# 4) 사용자가 undo를 선택하면 redo.append ( undo.pop() ) 를 수행한다.
# 5) 사용자가 redo를 선택하면 undo.append ( redo.pop() ) 를 수행한다.

undo = []
redo = []

undo.append (1)
undo.append (2)
undo.append (3)
redo.append ( undo.pop() )


print undo
print redo
Posted by chobocho
Coding/Java 삽질기2011. 6. 4. 19:56


즐거운 연휴~ 심심해서(?) 만들어 본 간단한 안드로이드용 퍼즐 게임



게임 방법

1. 빈 곳을 터치하면 상하좌우에서 동일한 이미지가 2개 있으면 삭제한다.
2. 빈 곳을 터치했으나 삭제할 수 있는 이미지가 없으면 타이머가 준다.
 
 
 

'Coding > Java 삽질기' 카테고리의 다른 글

Java에서 객체의 초기화 순서  (0) 2011.08.24
Android Tetris  (0) 2011.02.02
Bubble sort  (0) 2010.07.11
Posted by chobocho
Travel/Korea2011. 6. 1. 22:25

교과서에서만 보던, 석굴암을 수학 여행 이후 처음으로 가보았다.

아침부터 비가 오고, 안개가 자욱했다.

다음에는 날씨 좋은 날 다시 한 번 가봐야 겠다.

석굴암 출입구

석굴암 출입구

석굴암 앞 에서 본 모습

아침 부터 비가 내리고 안개가 자욱했던 석굴암 앞 전경


'Travel > Korea' 카테고리의 다른 글

태종대에서 본 최지우 부산 관광 사진전  (0) 2011.09.18
불국사  (0) 2011.05.31
태종대 유람선  (0) 2011.02.15
Posted by chobocho
Travel/Korea2011. 5. 31. 23:53


수학 여행 후 첨으로 불국사 구경을 다녀왔다.

비가 오고 흐린 날이었지만, 유명한 명소라서 그런지 관광객들로 붐볐다.

여행을 다니다 보니, 문득 국내에도 안 가본 곳이 너무 많다는 걸 다시 깨달았다.

시간 날 때마다, 구경을 가야겠다.
 

석가탑

석가탑


불국사를 설명하는 자료에 항상 첨부되는 이미지. 직접 가서 찍어 왔다.

'Travel > Korea' 카테고리의 다른 글

석굴암  (0) 2011.06.01
태종대 유람선  (0) 2011.02.15
부산 관광 사진전  (0) 2011.02.06
Posted by chobocho