SSC IMD SA 2017 – Question 196

Question:

Question Diagram

What is the output of this program?

What is the output of this program?

What is the output of this program? / इस प्रोग्राम का आउटपुट क्या है?

Question Diagram

What is the output of this program? / इस प्रोग्राम का आउटपुट क्या है?

Options:

  • Compilation error
  • Runtime error
  • Value of number is 10
  • None of these
  • कम्पाइलेशन एरर
  • रनटाइम त्रुटि
  • संख्या का मान 10 है
  • इनमे से कोई नहीं

Correct Answer: a)

Explanation:

Detailed Explanation:

The correct answer is a) Compilation Error (कम्पाइलेशन एरर).

Code Examination:

class PrintTest {
    public static void main(String args[])
    {
        int num = 10;
        if (NUM < 100) {
            System.out.println("The value of num is" + num);
        }
    }
}

Reason for Compilation Error:

  • Java is a strictly case-sensitive programming language. Identifiers, variable names, and keywords must precisely match their declaration in casing.
  • In line 4, the variable is declared and initialized in lowercase: int num = 10;.
  • In line 5, the condition attempts to reference the variable in uppercase: if (NUM < 100).
  • Because no identifier named NUM exists in the local or enclosing scope, the Java compiler (javac) halts with a compile-time error:
error: cannot find symbol
  variable NUM
  location: class PrintTest

Because this fault is identified during syntax/semantic compilation before any bytecode execution can take place, the result is a Compilation Error.

विस्तृत व्याख्या:

सही उत्तर a) कम्पाइलेशन एरर (Compilation Error) है।

कोड का विश्लेषण:

class PrintTest {
    public static void main(String args[])
    {
        int num = 10;
        if (NUM < 100) {
            System.out.println("The value of num is" + num);
        }
    }
}

त्रुटि का कारण:

  • जावा (Java) एक पूर्णतः केस-संवेदनशील (Case-sensitive) भाषा है। इसमें छोटे अक्षरों (lowercase) और बड़े अक्षरों (uppercase) को अलग-अलग माना जाता है।
  • पंक्ति 4 में चर को छोटे अक्षरों में घोषित किया गया है: int num = 10;।
  • किंतु पंक्ति 5 में if की शर्त में बड़े अक्षरों वाले NUM का उपयोग किया गया है: if (NUM < 100)।
  • चूँकि NUM नाम से कोई चर घोषित नहीं किया गया है, इसलिए कंपाइलर निम्नलिखित त्रुटि देता है:
    error: cannot find symbol: variable NUM।
  • यह त्रुटि प्रोग्राम के चलने से पहले कंपाइलेशन के दौरान ही आ जाती है, अतः इसका परिणाम कम्पाइलेशन एरर होगा।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top