当前位置: 代码迷 >> J2SE >> 求救!面试题!该如何解决
  详细解决方案

求救!面试题!该如何解决

热度:272   发布时间:2016-04-24 16:56:59.0
求救!面试题!!!
• Object-oriented   Design:   Explain   and   demonstrate   the   concept   of   Inheritance   and   Polymorphism   using   the   following   pseudo   Java   /   C#   /   C++   example:
o Base   Class:   Class   A,   has   method   “print”   that   outputs   “Class   A”
o Derived   Class:   Class   B   :   A,   has   method   “print”   that   outputs   “Class   B”
o Java   /   C#
 A   Instance1;   Instance1   =   new   A   ();   Instance1.print()   //   output   =   ?
 A   Instance2;   Instance2   =   new   B   ();   Instance2.print()   //   output   =   ?
 A   Instance3;   Instance3   =   (A)   new   B   ();   Instance3.print()   //   output   =   ?


------解决方案--------------------
 A Instance1; Instance1 = new A (); Instance1.print() // output = “Class A”
 A Instance2; Instance2 = new B (); Instance2.print() // output = “Class B”
 A Instance3; Instance3 = (A) new B (); Instance3.print() // output = “Class B”
  相关解决方案