JavaClassic2 / backlog

백로그 저장소
0 stars 0 forks source link

09. 자바에서의 상속 #23

Open siddltkfkd opened 3 months ago

siddltkfkd commented 3 months ago

interface

sub class

interface의 default 메소드와 static 메소드 default 메소드

C#의 상속

siddltkfkd commented 3 months ago
class A { 
    void m() {
        System.out.println("a"); 
    } 
}
class B extends A {
    void m() {
        System.out.println("b"); 
    }
}
class C extedns B {
    void m() {
        System.out.println("c"); 
    }
}
class D extends C {
    void m() {
        System.out.println("d"); 
    }
}

class Test {
    main() {
        D d = new D();
        C c = d;
        B b = c;
        A a = a;

        System.out.println(a.m());
        System.out.println(b.m());
        System.out.println(c.m());
        System.out.println(d.m());
    }
}
siddltkfkd commented 3 months ago
class A { 
    virtual void m() {
        System.out.println("a"); 
    } 
}
class B : A {
    override void m() {
        System.out.println("b"); 
    }
}
class C : B {
    new virtual void m() {
        System.out.println("c"); 
    }
}
class D : C {
    override void m() {
        System.out.println("d"); 
    }
}

class Test {
    main() {
        D d = new D();
        C c = d;
        B b = c;
        A a = a;

        System.out.println(a.m());
        System.out.println(b.m());
        System.out.println(c.m());
        System.out.println(d.m());
    }
}