हिंदी

What is meant by scope of variables? Show its application with the help of an example.

Advertisements
Advertisements

प्रश्न

What is meant by scope of variables? Show its application with the help of an example. 

कोड लेखन
लघु उत्तरीय
Advertisements

उत्तर

A static member is an instance variable that is global to the class. All class objects share a single copy of this data.

Example:

public class Stud{
static int count; // static variable
int x; // ordinary variable
void display()
{
System.out.println();
System.out.print("Count: " + ++count);
System.out.print(" X = " + ++x);
   }
   public static void main(String args[])
   {
   Stud ob1 = new Stud();
   ob1.display();
   Stud ob2 = new Stud();
   ob2.display();
   Stud ob3 = new Stud();
   ob3.display();
   }
}

Output:

Count:1 x=1
Count:2 x=1
Count:3 x=1

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 8: Encapsulation and Inheritance - EXERCISES [पृष्ठ ४४६]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 8 Encapsulation and Inheritance
EXERCISES | Q V. 12. | पृष्ठ ४४६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×