Page 269 - CA_Blue( J )_Class10
P. 269

11.5.4 Static Member Methods
                 A method that is declared within the class using the static keyword is called the static member method. Similar to a
                 static data member, the static member method can is accessed by using the class name. A static member method only
                 uses the static data members. For example:
                    static int s;
                    static void Show()
                    {
                        s= a+b;
                        System.out.println("The result is : " +s);
                    }

                 11.5.5 Constructors
                 Constructors are special methods with a name the same that of the class name. They are called automatically when
                 the object is created. They are used to initialize the instance of a class. For example:

                    class sum
                    {
                        int a, b;
                        sum()
                        {
                            a=0;
                            b=0;
                        }
                    }

                     11.6 NESTED CLASS
                 When a class is declared within another class then it is called a nested class. Let us consider the following example:
                    class employee                            // Main Class
                    {
                        String name, dept;
                        class salary                          // Nested Class
                        {
                            double basic, da, hra, pf, gross;
                            void accept()
                            {
                                basic = 5600;
                                da=0.5*basic;
                                hra=0.2*basic;
                                pf=0.0833*basic;
                            }
                            void display()
                            {
                                gross=basic + da + hra - pf;
                                System.out.println("Gross : "+gross);
                            }
                        }
                        salary ob1=new salary();
                        void take()
                        {
                            name="Amit Kumar";
                            dept="Computer";
                            ob1.accept();



                                                                                                                       267
                                                                                      Class as the Basis of all Computation  267
   264   265   266   267   268   269   270   271   272   273   274