출처: http://stackoverflow.com/questions/2223386/why-doesnt-java-allow-overriding-of-static-methods
Overriding depends on having an instance of a class. The point of polymorphism is that you can subclass a class and the objects implementing those subclasses will have different behaviors for the same methods defined in the superclass (and overridden in the subclasses). A static method is not associated with any instance of a class so the concept is not applicable.
Overriding depends on having an instance of a class. The point of polymorphism is that you can subclass a class and the objects implementing those subclasses will have different behaviors for the same methods defined in the superclass (and overridden in the subclasses). A static method is not associated with any instance of a class so the concept is not applicable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public class AA { public static void print() { System.out.println( "STATIC AA" ); } public void print2() { System.out.println( "AA" ); } } public class BB extends AA { public static void print() { System.out.println( "STATIC BB" ); } public void print2() { System.out.println( "BB" ); } public static void main(String[] args) { AA a = new BB(); a.print(); a.print2(); } } |
1 2 | STATIC AA BB |
'Archive' 카테고리의 다른 글
Agile 원칙 12가지 (0) | 2011.11.14 |
---|---|
다섯가지의 소프트웨어 테스트 (0) | 2011.11.14 |
Unit test와 functional test의 차이점 (0) | 2011.11.14 |
왜 inner class는 final local variable만 액세스 가능한가 (0) | 2011.11.14 |
두가지 대표적인 프로그래밍 스타일 (0) | 2011.11.10 |