Page 297 - COPA VOL II of II - TP -Punjabi
P. 297

1   ਕੰਸਟਰਕਟਰ ਦਾ ਨਾਮ ਇਸਦੇ ਕਲਾਸ ਨਾਮ ਦੇ ਸਮਾਨ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ
                                                                     ਨੋਟ: ਤੁਸੀਂ ਕੰਸਟ੍ਕਟ੍ ਘੋਸ਼ਭਤ ਕ੍ਦੇ ਸਮੇਂ ਐਕਸੈਸ ਮੋਡੀਫਾਇ੍
            2   ਇੱਕ ਕੰਸਟਰਕਟਰ ਕੋਲ ਕੋਈ ਸਪੱਸ਼ਟ ਿਾਪਸੀ ਕਭਸਮ ਨਹੀਂ ਹੋਣੀ ਚਾਹੀਦੀ  ਦੀ ਿ੍ਤੋਂ ਕ੍ ਸਕਦੇ ਹੋ। ਇਹ ਿਸਤੂ ਦੀ ੍ਚਨਾ ਨੂੰ ਨਭਯੰਤ੍ਭਤ
            3   ਇੱਕ  ਜਾਿਾ  ਕੰਸਟਰਕਟਰ  ਐਬਸਟ੍ਰੈਕਟ,  ਸਥਭਰ,  ਅੰਤਮ,  ਅਤੇ  ਸਮਕਾਲੀ   ਕ੍ਦਾ ਹੈ. ਦੂਜੇ ਸ਼ਬਦਾਂ ਿਭੱਚ, ਸਾਡੇ ਕੋਲ Java ਿਭੱਚ ਪਰ੍ਾਈਿੇਟ,
               ਨਹੀਂ ਹੋ ਸਕਦਾ ਹੈ                                      ਸੁ੍ੱਖਭਅਤ, ਜਨਤਕ ਜਾਂ ਡਭਫੌਲਟ ਕੰਸਟ੍ਕਟ੍ ਹੋ ਸਕਦਾ ਹੈ।


                                                        SOURCE CODE


                               // Java program to illustrate Constructor Chaining
                               // within same class Using this() keyword
                               class Temp
                               {
                                 // default constructor 1
                                / / default constructor will call another constructor
                                 // using this keyword from same class
                                 Temp()
                                {
                                     // calls constructor 2
                                     this(5);
                                     System.out.println(“The Default constructor”);
                                }

                                 // parameterized constructor 2
                                 Temp(int x)
                                {
                                     // calls constructor 3
                                     this(5, 15);
                                     System.out.println(x);
                                }

                                 // parameterized constructor 3
                                 Temp(int x, int y)
                                {
                                     System.out.println(x * y);
                                }

                                 public static void main(String args[])
                                {
                                        invokes default constructor
                                          //
                                     new Temp();
                                }
                               }




               Fig 1















                                      IT & ITES - COPA - (NSQF ਸੋਧੇ - 2022) - ਅਿਭਆਸ 1.41.20                    283
   292   293   294   295   296   297   298   299   300   301   302