Partage
  • Partager sur Facebook
  • Partager sur Twitter

constructor

    20 décembre 2014 à 18:40:32

    Hello

    I Have a question about constructor

    What is the main role of  constructor !

    & thank you in advance

    -
    Edité par akilaabbb 20 décembre 2014 à 18:43:00

    • Partager sur Facebook
    • Partager sur Twitter
      20 décembre 2014 à 18:56:28

      The goal of a constructor is to create an object of a specified class and to initialize all its fields.
      • Partager sur Facebook
      • Partager sur Twitter
        20 décembre 2014 à 19:22:45

        Hi, also there is two kind of constructor , the first is :  constructor without  initialization, the second is : constructor with initialization that initialize all the  fields of the object .
        • Partager sur Facebook
        • Partager sur Twitter
          20 décembre 2014 à 21:11:47

          A constructor always initializes all the fields of the object which is created. If no value is specified for a field, it is initialized to the default value for its type (0 for numbers, '\u0000' for characters, false for booleans and null for objects).
          • Partager sur Facebook
          • Partager sur Twitter
            21 décembre 2014 à 0:00:09

            also , if you don't define a default contructor , it is defined implicitelly , other thing is if you define a constructor with fields , and you don't define the default  constructor , yout get error by making  MyClass m=new MyClass() ; you are permeted to use just the contructor that you define explicitely
            • Partager sur Facebook
            • Partager sur Twitter
            Le succès n’est pas la clé du bonheur. Le bonheur est la clé du succès. Si vous aimez ce que vous faites, vous réussirez. Albert Schweitzer

            constructor

            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
            • Editeur
            • Markdown