Page 463 - Computer science 868 Class 12
P. 463

42            dis=amt*0.12;
                   43          else if(amt>=100000)

                   44            dis=amt*0.08;
                   45          else
                   46            dis=amt*0.05;

                   47         famt=amt-dis;

                   48        }
                   49        void print()
                   50        { super.print();

                   51          System.out.println("Discount Rs"+dis);
                   52          System.out.println("Amount to be paid Rs"+famt);

                   53      }
                   54      public static void main(char p,int h)

                   55      { Discount ob=new Discount(p,h);
                   56        ob.calnet();

                   57        ob.print();
                   58      }

                   59      }

                 The output of the preceding program is as follows:




















                     12.3 FUNCTION OVERLOADING AND POLYMORPHISM
                 Polymorphism is a combination of two Greek words: Poly (means many) and Morph (means forms). Polymorphism in
                 Java refers to the same object having multiple forms and attributes.

                 Let us take an example of a class called Shape. It can be a rectangle, circle, polygon or a star each having different
                 properties.
                                                                Class Shape







                                                                                                                       461
                                                                                  Inheritance, Interfaces and Polymorphism  461
   458   459   460   461   462   463   464   465   466   467   468