0

I am getting these 2 compiler errors :-

"There is no argument given that corresponds to the required parameter 'mark' of 'ParentClass.ParentClass(int)."

"'ChildInheritedClass' does not contain a constructor that takes 1 arguments."

Please let me know why this is happening.

using System;
namespace Fundas
{
 class ParentClass
 {
    int mark;
   public ParentClass(int mark)
   {
     this.mark = mark;
   }
  public void ParentClassMeth()
  {
     int perc = this.mark / 100;
    Console.WriteLine("The Percentage Obtained is : {0}", perc);
  }
}
 
 class ChildInheritedClass : ParentClass
 {
    static void Main(string[] args)
   {
       ChildInheritedClass obj = new ChildInheritedClass(600);
       obj.ParentClassMeth();
   }
 }
}
Abhishek Sharma
  • 113
  • 1
  • 4
  • 11
  • Does this answer your question? [How to inherit constructors?](https://stackoverflow.com/questions/223058/how-to-inherit-constructors) – shingo Jul 12 '23 at 04:11
  • Does this answer your question? [How to inherit constructors?](https://stackoverflow.com/questions/223058/how-to-inherit-constructors) – Fildor Jul 12 '23 at 04:49
  • You need to make an effort and try and understand the error messages. They quite clearly tell you what's wrong. And based on that, you could easily infer what to do: Implement a constructor in `ChildInheritedClass` that takes one parameter and passes it on to its base constructor. Additional hint: `static void Main` is _not_ a constructor. – Fildor Jul 12 '23 at 06:57

1 Answers1

0

"There is no argument given that corresponds to the required parameter 'mark' of 'ParentClass.ParentClass(int)."

because

public ParentClass(**int mark**)
   {
     this.mark = mark;
   }

"'ChildInheritedClass' does not contain a constructor that takes 1 arguments."

because

new ChildInheritedClass(**600**);

I just didn't understand why to call the class within itself

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 14 '23 at 12:22