편집 기록

편집 기록
  • 프로필 엽토군님의 편집
    날짜2020.01.23

    Java 왜 이런 결과가 나오는지 이해가 안갑니다.


    class Example {
        public static void main(String[] args) {
            Child child = new Child();
        } //main
    } // example
    
    
    class Parent{
        String nation;
    
        Parent() {
            this("대한민국");
            System.out.println("Parent() call");
        } 
        Parent(String nation) {
            this.nation = nation;
            System.out.println("Parent(String nation) call");
        } 
    
    } // class parent
    
    class Child extends Parent {
        String name;
    
        Child() {
            this("홍길동");
            System.out.println("Child() call");
        } 
        Child(String name) {
            this.name = name;
            System.out.println("Child(String name) call");
        } 
    
    
    
    } // class child
    

    이렇게 작성하고 실행하면 main에서는 그저 child 라는 새로운 객체를 만들었을뿐인데 왜 모든 println이 작동하는지 모르겠습니다. 그 순서또한 이해가 안갑니다.

  • 프로필 편집요청빌런님의 편집
    날짜2020.01.23

    Java 왜 이런 결과가 나오는지 이해가 안갑니다.


    public class Example {
        public static void main(String[] args) {
            Child child = new Child();
        } //main
    } // example
    
    class Parent{
        String nation;
    
        Parent() {
            this("대한민국");
            System.out.println("Parent() call");
        } 
        Parent(String nation) {
            this.nation = nation;
            System.out.println("Parent(String nation) call");
        } 
    
    } // class parent
    
    class Child extends Parent {
        String name;
    
        Child() {
            this("홍길동");
            System.out.println("Child() call");
        } 
        Child(String name) {
            this.name = name;
            System.out.println("Child(String name) call");
        }   
    } // class child
    

    이렇게 작성하고 실행하면 main에서는 그저 child 라는 새로운 객체를 만들었을뿐인데 왜 모든 println이 작동하는지 모르겠습니다. 그 순서또한 이해가 안갑니다.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.01.22

    Java 왜 이런 결과가 나오는지 이해가 안갑니다.


    class Example { public static void main(String[] args) { Child child = new Child(); } //main } // example

    class Parent{ String nation;

    Parent() {
        this("대한민국");
        System.out.println("Parent() call");
    } 
    Parent(String nation) {
        this.nation = nation;
        System.out.println("Parent(String nation) call");
    } 
    

    } // class parent

    class Child extends Parent { String name;

    Child() {
        this("홍길동");
        System.out.println("Child() call");
    } 
    Child(String name) {
        this.name = name;
        System.out.println("Child(String name) call");
    } 
    

    } // class child

    이렇게 작성하고 실행하면 main에서는 그저 child 라는 새로운 객체를 만들었을뿐인데 왜 모든 println이 작동하는지 모르겠습니다. 그 순서또한 이해가 안갑니다.