trews

trews

  • 0
  • 1
  • 0

About Inheritance

Nov 26 2008 1:42 AM

Hello,

I am a beginner. Inheritance is somehow hard to understand.

Example Code:

class zzz
{
 public static void Main()
 {
  xxx a = new xxx();
  a.abc();
 }
}

class yyy
{
 public int i = 10;
 public void abc()
 {
  System.Console.WriteLine("yyy abc");
 }
 public void pqr()
 {
  System.Console.WriteLine("yyy pqr");
 }
}

class xxx : yyy
{
}

 

Q.1) xxx class is derived from the yyy class. Are the codes that belongs to the parent class(yyy) copied or inserted to the derived class(xxx) while compiling these codes? Or is the abc() method just a reference to the abc() method in yyy?

 

Q.2) If the codes are copied to the derived class from the parent class, why does the constructor of yyy class get called?

 

Q.3) Why is the constructor of yyy get called before the xxx's? Where and when do we use this?

 

Thanks.


Answers (2)