C# override

Class may have methods with the same name but different parameter numbers or types, which is overriding.

class A
{
public int i;
public string str;
public A() { i = 2; }
public string irate(double d)
{
double d2 = i * (1 + d);
return d2.ToString();
}
public string irate(string s) //overrided method irate
{
return s;
}
}

An inherited class can override the methods of the base class, especially the constructor.
class human
{
public int age;
public string sex;
public human(int a, string s) {age=a;sex=s;}
}
class student : human
{
int grade;
public student(int a, string s, int g)
: base(a, s)
{ age = a; sex = s; grade = g; }
}



endmemo.com © 2024  | Terms of Use | Privacy | Home