Posts

Showing posts with the label java variable scope

Scope of a variable in java जावा में वेरिएबल का कार्यक्षेत्र

In Java, the scope of a variable refers to the region in a program where the variable is recognized and accessible. Variables in Java can be categorized based on their scope into three main types: जावा में वेरिएबल का कार्यक्षेत्र उस हिस्से को कहा जाता है जहाँ वेरिएबल मान्य और उपयोग योग्य होता है। जावा में वेरिएबल के कार्यक्षेत्र को तीन प्रमुख वर्गों में बांटा गया है– 1️⃣ Local Variable (लोकल वेरिएबल) English: Declared and used only inside a method or a block {} . Scope is limited to that method or block. Dies as soon as the control exits the method. Java does not allow same-name variables in nested blocks unlike C/C++. Hindi: यह किसी मेथड या ब्लॉक {} के अंदर ही घोषित और उपयोग किए जाते हैं। इनका कार्यक्षेत्र उसी मेथड या ब्लॉक तक सीमित होता है। जैसे ही कंट्रोल बाहर जाता है, यह समाप्त हो जाते हैं। जावा में नेस्टेड ब्लॉक्स में एक ही नाम के दो वेरिएबल नहीं बनाए जा सकते हैं। 2️⃣ Instance Variable (इंस्टैंस वेरिएबल) English: Declared inside a class but...

Variables in Java जावा में वेरिएबल

In Java, a variable is a named storage location used to hold data values during program execution. Variables are essential because they allow you to store, update, and use data dynamically. जावा में वेरिएबल (चर) एक नामित स्टोरेज स्थान होता है, जिसका उपयोग प्रोग्राम के दौरान डेटा को संग्रहित और उपयोग करने के लिए किया जाता है। वेरिएबल्स प्रोग्रामिंग का एक मूलभूत हिस्सा होते हैं। 🔹 1. Declaration | घोषणा Before using a variable, it must be declared with its data type and name. किसी वेरिएबल का उपयोग करने से पहले, उसका डेटा प्रकार और नाम बताकर उसे घोषित (declare) करना होता है। int age; // Declare an integer variable named 'age' 🔹 2. Initialization | मान देना After declaring, you can assign a value. This is called initialization . घोषणा के बाद, वेरिएबल को कोई मान (value) देना Initialization कहलाता है। age = 50; // Initialize the variable Declaration and initialization can also be done together: int age = 50; 🔹 3. Variable Types | वेरिएबल के प्रकार Java is stati...