0

So I haven been learning Java for a while but decided to switch to C#. It's been a while so I may forget some things. What I know is that in Java, when inheriting from a super class you can or can not call the super class and pass in the parameter if it accepts it. For example:

public class Super
{
    public Super(int x)
    {
    }
}

public class Sub extends Super
{
    public Sub()
    {
        super(5);
    }
}

and then this other example:

public class Super
{
    public Super(int x)
    {
    }
}

public class Sub extends Super
{
    public Sub()
    {

    }
}

is also totally fine since it does not have to pass in parameter to the superclass, correct me if I am wrong. But then in C#, I am not sure if you are required to pass in the parameter for the superclass or not(like if it is still legal and won't cause any problem)

genedev
  • 1
  • 1
  • you can pass parameter like: class (param) : base(param) – Michael Gabbay Jun 09 '20 at 00:02
  • 1
    `But then in C#, I am not sure if you are required to pass in the parameter for the superclass or not` **"Try it and see"** would be my recommendation. https://dotnetfiddle.net/kK7TfK – mjwills Jun 09 '20 at 00:03
  • Yes, you are wrong about Java. Your second code snippet does not compile as you are required to pass the parameter to the superclass constructor. – Erwin Bolwidt Jun 09 '20 at 02:27

0 Answers0