Monday, May 23, 2011

Inheritance


When we are calling the object of child class. always constructor of base class calls the first

In desctructor it is always first desctuct the child object than parent

A a2 = new B();      allowed

but we can not give reference of parent to child.


as int are structs and cannot have reference to object
int is using IEquatable interface to implement
which contains Equals method through which int can chek equality comparison there.

***************************************
namespace Test2
{
 public class A
 {
  public A()
  {
   Console.WriteLine("This class A");
  }
 }
 
 public class B : A 
 {
  public B()
  {
   Console.WriteLine("This class B");
  }
 }
 
 
 public class C : B
 {
  public C()
  {
   Console.WriteLine("This class C");
  }
 }
}




namespace Test2
{
 class Program
 {
  static void Main(string[] args)
  {
   A a = new A();
   System.Console.Read();
   B b = new B();
   System.Console.Read();
   C cC1 = new C();
   System.Console.Read();
  }
 }
}

No comments:

Post a Comment