Page 465 - Computer science 868 Class 12
P. 465

12      }
                   13      public static void main(int b1,int h1,int aa,int bb,int cc)

                   14      { TriOverload ob=new TriOverload();
                   15        System.out.println("Best match is base class method with two parameters");
                   16        ob.calarea(b1,h1);

                   17        System.out.println("Best match is derived class method with three parameters");

                   18        ob.calarea(aa,bb,cc);
                   19      }
                   20      }

                 The output of the preceding program is as follows:














                 From the above output, we find that in first method call, two integer arguments are passed which matches with the
                 base class method and is executed.

                 In second method call, three integer arguments match with the derived class method parameter and thus executed.

                   Program 7     A super class called ArrayB is defined as follows:
                                 Class name                     :  ArrayB
                                 Data Members
                                 int arr[]                      :  An array containing 10 numbers
                                 Member Methods
                                 ArrayB((int x[])               :  Parameterised constructor to initialise data member
                                 boolean searcharray(int n)     :   Searches if the number stored in variable ‘n’ is present
                                                                   in the array or not and returns true or false accordingly
                                 A subclass called ArrayD is defined whether the numbers in the array belong to a given range.
                                 The details are given below.
                                 Class name                     :  ArrayD
                                 Member Methods
                                 ArrayD(int x[])                :  Parameterised constructor to initialise data member
                                 boolean searcharray(int x,int y)   :   Checks if all the numbers in the array are greater than x
                                                                   and less than y or not
                                                                   That is, x< arr[i] < y
                                                                   The method returns either true or false
                                 void display()                 :  Displays the array

                   1       class ArrayB
                   2       { int arr[]=new int[10];



                                                                                                                       463
                                                                                  Inheritance, Interfaces and Polymorphism  463
   460   461   462   463   464   465   466   467   468   469   470