मराठी

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

Advertisements
Advertisements

प्रश्न

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

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

उत्तर

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×