메소드 오버라이딩

(오버라이드에서 넘어옴)

1 개요[ | ]

method overriding, override
메소드 오버라이딩; 오버라이딩, 오버라이드

2 실습 예제[ | ]

소스 코드
class Base {
  Base() { System.out .println ("Base: Base"); }
  void print() { System.out .println ("Base: print"); }
  static void staticPrint() { System.out .println ("Base: staticPrint"); }
}
class Derived extends Base {
  Derived() {System.out .println ("Derived: Derived"); }
  void print() {System.out .println ("Derived: print"); }
  static void staticPrint() {System.out .println ("Derived: staticPrint"); }
}
public class Main {
  public static void main (String[] args) {
    Base base = new Base();
    base.print();
 
    Derived derived = new Derived();
    derived .print();
 
    Base derivedInBaseVariable = new Derived();
    derivedInBaseVariable.print();
 
    Base.staticPrint();
    Derived.staticPrint();
  }
}
실행 결과
Base: Base
Base: print
Base: Base
Derived: Derived
Derived: print
Base: Base
Derived: Derived
Derived: print
Base: staticPrint
Derived: staticPrint

3 같이 보기[ | ]

4 주석[ | ]

  1. 다르면 오버로딩이 되겠지...

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}