Java, I don't understand why this is happening.

Asked 2 years ago, Updated 2 years ago, 25 views

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


class Parent{
    String nation;

    Parent() {
        this ("South Korea");
        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 ("Hong Gil-dong");
        System.out.println("Child() call");
    } 
    Child(String name) {
        this.name = name;
        System.out.println("Child(String name) call");
    } 



} } // class child

When you create and run it like this, main just created a new object called child, but I don't know why all println works. I don't understand the order either.

java

2022-09-22 14:52

1 Answers

Finished


2022-09-22 14:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.