예제 #1
0
 private void button4_Click(object sender, EventArgs e)
 {
     HandleClass6 h = new HandleClass6();
     Class7 c7 = new Class7();
     //Class6 parent = c7;
     //h.GetClass6String(parent);
    MessageBox.Show( h.GetClass6String(c7));
 }
예제 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            Class6 parent;

            Class7 c7 = new Class7();
            parent = c7; //上溯造型,父类(接口)变量指向子类对象。
           MessageBox.Show(parent.GetString());
            MessageBox.Show(parent.GetStringEx());

            //Class8 c8 = new Class8();
            //parent = c8;
            //MessageBox.Show(parent.GetString());
        }
예제 #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            HandleClass6 h = new HandleClass6();
            Class7 childObj = new Class7();

            Class6 parentPnt = childObj;

            MessageBox.Show(parentPnt.GetString()); // virtual
            MessageBox.Show(parentPnt.GetStringEx());
            
            
            
            ////父类变量指向之类的对象,上溯造型
            ////由父类变量实现的方法调用,如果该方法是虚方法,并且子类中实现override,那么
            ////调用的实际上就是子类方法。
            //Class6 newobj = new Class14();
            ////reflection
            ////MEF

            //MessageBox.Show(h.GetClass6String(newobj));//?

        }