今天的一道面試題糗大了

來源:互聯網
上載者:User

  現在有如下代碼,請問執行個體化B類,將輸出什嗎?也就是在Main方法中執行B b=new B();時,將輸出什嗎?我知道將輸出的不是y=0就是y=-1。不難吧!可惜我做錯了,你能不在電腦上運行一遍,做出準確的答案嗎?  

public class A    {        public A()        {            A1();        }        public virtual void A1()        { }    }    public class B : A    {        Int32 x = 1;        Int32 y;        public B()        {            y = -1;        }        //重寫A類的A1方法        public override void A1()        {            Console.WriteLine("x={0},y={1}",x,y);        }    }

  不知道請舉手,自賞三耳光,嘿嘿。。。
  還有好多面試題是出自這位都老兄收集的面試題裡面,地址:http://www.cnblogs.com/zengxiangzhan/archive/2010/04/23/1718521.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.