Which keyword is used to create an instance of a class in most programming…

2025

Which keyword is used to create an instance of a class in most programming languages?

  1. A.

    alloc

  2. B.

    new

  3. C.

    create

  4. D.

    instance

Attempted by 1122 students.

Show answer & explanation

Correct answer: B

In most programming languages, the keyword 'new' is used to create an instance of a class. It allocates memory for the object and calls the constructor to initialize it. This is a standard practice in languages like Java, C#, and JavaScript.

Option A: 'alloc' is used in Objective-C for memory allocation, but it does not initialize the object or call constructors, so it is not the standard keyword for instance creation.

Option B: 'new' is the correct keyword in most languages. It creates a new instance by allocating memory and calling the constructor, making it the standard choice.

Option C: 'create' is not a standard keyword in most languages. While some languages may use it in specific contexts, it is not universally recognized for creating class instances.

Option D: 'instance' is a noun, not a keyword. It refers to the object itself, not the action of creating it, so it cannot be used to instantiate a class.

हिन्दी उत्तर:

अधिकांश प्रोग्रामिंग भाषाओं में, क्लास का इंस्टेंस बनाने के लिए 'new' कीवर्ड का उपयोग किया जाता है। यह ऑब्जेक्ट के लिए मेमोरी आवंटित करता है और इसे इनिशियलाइज करने के लिए कंस्ट्रक्टर को कॉल करता है। यह जावा, सी#, और जावास्क्रिप्ट जैसी भाषाओं में मानक व्यवहार है।

विकल्प A: 'alloc' ऑब्जेक्टिव-सी में मेमोरी आवंटन के लिए उपयोग किया जाता है, लेकिन यह ऑब्जेक्ट को इनिशियलाइज नहीं करता और कंस्ट्रक्टर को कॉल नहीं करता, इसलिए यह इंस्टेंस बनाने के लिए मानक कीवर्ड नहीं है।

विकल्प B: 'new' अधिकांश भाषाओं में सही कीवर्ड है। यह नया इंस्टेंस बनाता है जो मेमोरी आवंटित करता है और कंस्ट्रक्टर को कॉल करता है, जिससे यह मानक चुनाव बनता है।

विकल्प C: 'create' अधिकांश भाषाओं में मानक कीवर्ड नहीं है। हालांकि कुछ भाषाएं इसे विशिष्ट संदर्भों में उपयोग कर सकती हैं, लेकिन यह क्लास इंस्टेंस बनाने के लिए सार्वभौमिक रूप से मान्य नहीं है।

विकल्प D: 'instance' एक संज्ञा है, कीवर्ड नहीं। यह ऑब्जेक्ट को संदर्भित करता है, न कि इसे बनाने की क्रिया, इसलिए इसे क्लास का इंस्टेंस बनाने के लिए उपयोग नहीं किया जा सकता।

Explore the full course: Bpsc