Héritage, polymorphie et surcharge

Résolu
Kleino Messages postés 5 Date d'inscription mercredi 18 mars 2009 Statut Membre Dernière intervention 30 mars 2009 - 25 mars 2009 à 15:21
Kleino Messages postés 5 Date d'inscription mercredi 18 mars 2009 Statut Membre Dernière intervention 30 mars 2009 - 30 mars 2009 à 07:45
Slt á ts,
je suis nouveau et travaille les heritages, la polymorphie et les surcharges en c#
Cependant je suis coincé
et récolte cette erreur: Method must have a return typ
j´ai utilisé return, ou bien console.out... mais en vain!

Ci dessous mon code:
public class personne

        {

            // attributs de classe

            private static long _nbPersonnes = 0;

            // attributs d'instance

            private String _prenom;

            private String _nom;

            private int _age;

            // constructeurs

            public personne(String P, String N, int age)

            {

                // une personne de plus

                _nbPersonnes++;

                this._prenom = P;

                this._nom = N;

                this._age = age;

            }

            public personne(personne P)

            {

                // une personne de plus

                _nbPersonnes++;

                this._prenom = P._prenom;

                this._nom = P._nom;

                this._age = P._age;

            }

            // identifie

            public void identifie()

            {

                Console.Out.WriteLine(_prenom + "," + _nom + "," + _age);

                //Console.Read();

            }


            ///////Nur für Vererbung, polymorphismus und overloading gedacht

            public string identite

            {

                get { return "personne(" + _prenom + "," + _nom + "," + age + ")"; }

           

            }

            // propriété de classe

            public static long nbPersonnes

            {

                get { return _nbPersonnes; }

            }//nbPersonnes

            // propriétés d'instance

            public string prenom

            {

                get { return _prenom; }

                set { _prenom = value; }

            }//prenom

            public string nom

            {

                get { return _nom; }

                set { _nom = value; }

            }//nom

            public int age

            {

                get { return _age; }

                set

                {

                    // age valide ?

                    if (value >= 0)

                    {

                        _age = value;

                    }

                    else

                        throw new Exception("âge (" + value + ") invalide");

                }//if

            }


public class enseignant : personne {

                // attributs

            private int _section;

// constructeur

        public enseignant(string P, string N, int age,int section) : base(P,N,age)

        {

        this._section=section;

// suivi

            Console.Out.WriteLine("Construction enseignant(string,string,int,int)");

            Console.Read();

        }//constructeur

// propriété section

        public int section{

            get { return _section; }

            set { _section=value; }

        }// section

    }


 public Object ();

            

// Methods

        public virtual bool Equals(object obj);

        public static bool Equals(object objA, object objB);

            public virtual int GetHashCode();

        public Type GetType();

        public static bool ReferenceEquals(object objA, object objB);

        public virtual string ToString();

        

            

}

public class test1

        {

        public static void Main()

        {

                ////////////////////OVERLAOD EINER PROPRIETÄT

        Console.Out.WriteLine(new enseignant("Lucile","Dumas",56,61).ToString());

// eine person

        Console.Out.WriteLine(new personne("Jean","Dupont",30).ToString());

        }

    }

    }

Merci bien
Kleino

3 réponses

Kleino Messages postés 5 Date d'inscription mercredi 18 mars 2009 Statut Membre Dernière intervention 30 mars 2009
30 mars 2009 à 07:45
Slt á ts et merci bcp ca a marché.
Désolé si je ne me suis pas annoncé depuis.
3
ed73 Messages postés 276 Date d'inscription lundi 8 septembre 2008 Statut Membre Dernière intervention 15 avril 2013 2
25 mars 2009 à 15:51
Ca vient de

public Object ();

A priori ça ne sert à rien dans ton code.
0
nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
25 mars 2009 à 17:15
Salut

Tout le code suivant ne sert pas

 public Object ();
            
// Methods
        public virtual bool Equals(object obj);
        public static bool Equals(object objA, object objB);
            public virtual int GetHashCode();
        public Type GetType();
        public static bool ReferenceEquals(object objA, object objB);
        public virtual string ToString()

Et ou est l'erreur
0
Rejoignez-nous