What is Constructor Overloading in JAVA-hindi ?-vishmy1.blogspot.com

Constructor Overloading in JAVA

Like method, Constructor can also be overloaded, Sometimes there is a need of initializing of an object in different ways this can be done using Constructor Overloading.

विधि की तरह, कन्स्ट्रक्टर को भी अधिभारित किया जा सकता है, कभी-कभी किसी ऑब्जेक्ट को अलग-अलग तरीके से शुरू करने की आवश्यकता होती है, यह कन्स्ट्रक्टर ओवरलोडिंग का उपयोग करके किया जा सकता है।

Constructor Overloading is a concept of having more than one constructor with different parameter list, in such a way so that each constructor can perform a different task.

कन्स्ट्रक्टर ओवरलोडिंग विभिन्न पैरामीटर सूची के साथ एक से अधिक कंस्ट्रक्टर होने की एक अवधारणा है, इस तरह से ताकि प्रत्येक कंस्ट्रक्टर एक अलग कार्य कर सके।

Constructor Overloading means same Constructor can be declare into the same class with the different parameter list.

कन्स्ट्रक्टर ओवरलोडिंग का अर्थ है एक ही कन्स्ट्रक्टर को अलग-अलग पैरामीटर सूची के साथ एक ही कक्षा में घोषित किया जा सकता है।

Compiler differentiate which constructor  is to be called depending upon the number of parameters and their sequence of datatypes.

कंपाइलर अंतर करता है कि कौन से निर्माता को डेटा प्रकारों के मापदंडों और उनके अनुक्रम के आधार पर बुलाया जाना है।

What is Constructor Overloading  in JAVA-hindi ?-vishmy1.blogspot.com
Constructor Overloading


ex :-

Here we are overloading 4 constructors with different arguments.

यहां हम अलग-अलग तर्कों के साथ 4 कंस्ट्रक्टरों को ओवरलोड कर रहे हैं।

class test
{
    test()
    {
         System.out.println("Constructor with no argument :");
    }
    test(String s)
    {
         System.out.println("Constructor with one arguments :");
     }
     test(int a, int b)
     {
          System.out.println(a+b);
      }
     public static void main(String args[])
     {
           test t = new test();
           test t1 = new test(10, 20);
           test t2 = new test("vishal");
     }
}

ex  2:- 

This is the 2nd example of the Constructor Overloading in which we are going to see the use of this instance.

यह कंस्ट्रक्टर ओवरलोडिंग का दूसरा उदाहरण है जिसमें हम इस उदाहरण का उपयोग देखने जा रहे हैं।

class test 
{
     int x, y;
     test(int p, int q)
     {
          this.x = p;
          this.y = q;
      }
      void display() 
      {
            System.out.println(x);
            System.out.println(y);
       }
      public static void main(String args[])
      {
           test t = new test(10, 20);
           t.display();
      }
}

Note : - IN the next Blog I'm going to explain about this and super keywords which is one of the most important topic in JAVA.

अगले ब्लॉग में मैं इसके और सुपर कीवर्ड्स के बारे में बताने जा रहा हूँ जो JAVA के सबसे महत्वपूर्ण विषय में से एक है।

and if you guys want to know about any topic then comment in the comment section, then I'll explain that topic.

और यदि आप लोग किसी भी विषय के बारे में जानना चाहते हैं तो टिप्पणी अनुभाग में टिप्पणी करें, फिर मैं उस विषय को समझाऊंगा।

for more updates subscribe to my blog to get a notification when my blog is uploaded & you can help your friends by sharing it with them.

अधिक अपडेट के लिए, मेरे अपलोड होने पर सूचना प्राप्त करने के लिए मेरे ब्लॉग की सदस्यता लें। और आप अपने दोस्तों को उनके साथ साझा करके मदद कर सकते हैं।


       Thank you!!!



Post a Comment

2 Comments

  1. Very helpful thank you so much for this Post

    ReplyDelete
  2. Awesome post
    Agar aapko hindi punjnabi marathi tamil bhojpuri song ya singer pasand ha to niche diye hue link par jake unke koi bhi song ya kisi bhi song ko search krke unki lyrics dekh sakte ha

    hindi song lyrics punjabi song lyrics english song lyrics new song lyrics

    ReplyDelete