Page 350 - CA_Blue( J )_Class10
P. 350

11      void display()
                12      {

                13          int f=1,i;
                14          for(i=1;i<=n; i++)

                15      {
                16          f=f*i;

                17      }
                18      System.out.println("Factorial : "+f);

                19      }
                20  }

              Explanation: Here, f and i in display () method are local variables as the scope of the variables exist within the method
              body.

              14.3.2 Class Variables
              Class variables are also known as static data members. Only one copy is created for all the objects of the class thus
              having a single value of the variable for all the objects. It is common to all the objects of the class. Examples of class
              variables are:

                  static int a;
                  static double b;
                Program 5    To count the number of objects created.


                 1  import java.util.*;

                 2  class count_object
                 3  {

                 4      static int c;
                 5      void increase()

                 6      {
                 7         c++;

                 8         System.out.println("Object Number : "+c);

                 9      }
                10      public static void main()
                11      {

                12         Scanner sc= new Scanner(System.in);
                13         char n;

                14         while(true)
                15         {





                348348  Touchpad Computer Applications-X
   345   346   347   348   349   350   351   352   353   354   355