Page 260 - ComputerScience_Class_11
P. 260

f=f*i;
                          }
                      }

                      void display ()
                      {
                          calculate();
                          System.out.println("Factorial:" +f);
                      }
                  }
              Let us discuss some of the important terms mentioned above.
              a. Access Specifier: To get accessed in different ways, we need an Access specifier. The three-access specifiers are:
                 Public, Protected and Private. They are also known as Visibility modes.
                •  Public: Methods and variables when declared public can be used within a class as well as outside the class. If the
                   access specifier is not mentioned, then by default it is taken as public.
                  E.g., public int a, b, s=0;
                •  Private:  Data members and variables declared as private can be accessed only from within the scope of the class.
                  E.g., private int radius, area, perimeter;
                •  Protected: When we declare data members and methods as protected, then the members can not only be
                   accessed from the same class but also from the inherited class.
                  E.g., protected int length, breadth;
              b. Class: It is a reserved word that is used to declare a class.
              c.  Name of the class: It is used to give a name to define the class so that it can be easily referred to when required.
              d. Data Members: They are the variables described within a class and can be used to store values whenever required.
              e. Member Methods: The defined methods in a class are termed as Member Methods. These methods have some
                 stored values which are used as global variables and these variables are also used to perform some jobs.
              Apart from the above mentioned, there are two parts of a class which are as follows:
              a. External Wrapper: The whole class is encapsulated in a bracket. It contains the reserved word “class” and the class
                 name.
              b. Internal Wrapper: Whatever is contained in the braces after the class name, is the Internal Wrapper. It contains the
                 instance variable, class variable, local variable, constructor and member methods.
                •  Instance Variable: It is a non-static data member that is  created whenever any object is generated. All instance
                   variables are accessed by preceding it with the object name.
                  For example,
                      char ch;
                      short s;
                •  Class Variable: It is also known as a static data member or static variable which is capable of creating only one copy
                   for all the objects of the class. Thus, there would be only one copy of the variable per class, no matter the number
                   of objects that may be created from it.
                  For example,
                      static int a;
                      static double b;
                  Differences between ordinary and static data members are as follows:
                                Ordinary Data Members                           Static Data Members
                    All  objects  created  have  individual  data  members  Only  one  copy  of  the  data  members  is  used  by  all  the
                    assigned to them.                            objects created.
                    Any change in the value stored in a data member will  Any change made in a static data member through an object
                    affect only the respective object.           will affect the common data members of all the  objects.



                  258  Touchpad Computer Science (Ver. 3.0)-XI
   255   256   257   258   259   260   261   262   263   264   265