Yadlapalli Srikanth

Yadlapalli Srikanth

  • NA
  • 272
  • 82.9k

access supper class method with the instance hirarical base

Jan 8 2015 4:15 AM
Dear All,

I faced one interview question in polaris, They asked me to print the virtual method of the super class with the instance of B class. Is it possible by casting? if so please try and let me know.  



class hirarical
  {
  public virtual void print()
  {
  Console.WriteLine("print virtual method");
  }
  public  void printnorm()
  {
  Console.WriteLine("print virtual method");
  }
  }
  class a : hirarical
  {
  public override void print()
  {
  Console.WriteLine("print a method");
  //base.print();
  }
  }
  class B : a
  {
  public override void print()
  {
  //need to access the virtual method of hierarical class with B instance can do casting with B instance
  Console.WriteLine("print B method");

  }
  }

//need to access the

Answers (3)