日期:2014-05-17  浏览次数:20775 次

一个类New出的对象转换为其接口的类型那转换后的对象含有该接口没要求实现的成员变量和成员方法的引用吗?
一个类New出的对象转换为其接口的类型那转换后的对象含有该接口没要求实现的成员变量和成员方法的引用吗?namespace test1
{
    public interface iface
    {

        iface add(a t);
       
    }
    public class a:iface
    {
       public static int f = 3;
       public int c;
       private int b;
        int w;
        iface p;
        public a(int x, int y, int z)
        {
            c = x;
            b = y;
            w = z;
        }
        public void r()
        {
            Console.WriteLine("enumerable{0}",c);
        }
        public void d()
        {
            Console.WriteLine("hello world!");
        }
              public iface add(a tt)
        {
            p = tt;
            Console.WriteLine("add is world!{0}",c);
            r();
            return p;
        }
    
    }
    public class Program
    {
        public int j;
        public Program(int t)
        {
            this.j = t;
        }
        static void Main(string[] args)
        {
            Program a=new Program(1);
           a t = new a(2, 3, 4);
             iface p1 = (iface)t;//如这个p1他还含有f,c,b,p等成员变量以及add方法以外的其他方法的引用吗!如果没有,为什么我按F11去查看p1时候在里面展开的项目中发现有f,c,b,p等成员变量呢!
           
------解决方案--------------------
算是隐藏起来了吧,这里主要体现了面向对象编程的多态,看下给你回复的收件箱