18
mai
2007
Sous-classe appel des méthodes parentes
mai
2007
Le code suivant fonctionne sans problème :
class Test
{
static void Toto(string s1)
{
}
class SubTest
{
static void Tutu()
{
Toto("un");
}
}
}
{
static void Toto(string s1)
{
}
class SubTest
{
static void Tutu()
{
Toto("un");
}
}
}
En revanche le code suivant
class Test
{
static void Toto(string s1)
{
}
class SubTest
{
static void Tutu()
{
Toto("un");
}
static void Toto(string s1, string s2)
{
}
}
}
{
static void Toto(string s1)
{
}
class SubTest
{
static void Tutu()
{
Toto("un");
}
static void Toto(string s1, string s2)
{
}
}
}
génère une erreur à la compilation (« No overload for method ‘Toto’ takes ‘1’ arguments »)
On pourra regretter que le compilateur n’aille pas chercher dans la classe parent à partir du moment où une méthode portant le même nom mais n’ayant pas la même signature est définie dans la classe fille.