Java Programming

Java virtual function(?)

tomato13 2008. 6. 25. 12:03

http://kin.naver.com/detail/detail.php?d1id=1&dir_id=10106&eid=z0dyJyg5gf8tdxKZNd7eBwiUHL7drnsI&qb=amF2YSCwobvzIMfUvPY=&pid=fbb0SloQsCGsscicpGwsss--230668&sid=SGG0P358YUgAAB7COzA

 

C++과 다르게 별도의 'virtual'이라는 keyword를 명시하지 않아도 parent class를 child class로 재정의하여 필요한 함수를 사용할 수 있는 듯 하다.

 

interface CA {
    public int m_Func();
}

 

class CA_Child1 implements CA {
    public int m_Func() {
        System.out.print("This is CA_Child1.\n");
       
        return 1;
    }
}

 

class CA_Child2 extends CA_Child1 {
    @Override
    public int m_Func() {
        System.out.print("This is CA_Child2.\n");
       
        return 1;
    }
}

 

public class CExec {    
    public int m_Exec2()    {
        CA_Child1 l_oCA_Child1 = new CA_Child1();
        l_oCA_Child1 = new CA_Child2();
       
        l_oCA_Child1.m_Func();
              
        return 1;
    }

}

 

'Java Programming' 카테고리의 다른 글

Java 'synchronized' method  (0) 2008.06.27
java의 synchronized 분석  (0) 2008.06.27
Interface class에 대한 implementation(child, grandchild)  (0) 2008.06.25
Java multiple inheritance  (0) 2008.06.24
Mutual Exclusion Control  (0) 2008.06.23