Seshadri M

Seshadri M

  • NA
  • 69
  • 18.1k

Dervied class Constructor value pass to parent class

Sep 18 2017 3:03 AM

I am trying to pass the value from child class to parent class constructor. But

class Class1
{

public Class1(int a, int b) {
this.a = a;
this.b = b;
Console.WriteLine("parentconstructor");
}
}
class Class2: Class1 { 
public Class2(int a, int b): base(a, b) {
Console.WriteLine("childconstructor");
}
}
 
 class program
{
 class2 obj =new class2( 4,5);
Console.ReadLine(); 
}
 
//OUTPUT
//Parentconstructor
//childconstriuctor 
// But excepted child constructor first an second parentconstructor 
 

Answers (4)