Page 493 - Computer science 868 Class 12
P. 493

Highest(int cap)
                      {
                      super(cap);
                      readarray();
                      }
                      public void find()
                      { ind = 0;
                      for (int i = 0; i < size; i++)
                      { if(m[i]>m[ind])
                        {  ind = i; }
                        }
                      }
                      public void display() {
                      super.display();
                      System.out.println("Highest marks " +m[ind]);
                      System.out.println("Students who scored highest marks are");
                      for (int i = 0; i < size; i++)
                      if(m[i] == m[ind]) {
                      System.out.println(n[i]);
                        }
                      }
                      public static void main(int s)
                      { Highest ob=new Highest(s);
                        ob.find();
                        ob.display();
                        }
                      }









                   10.  What are Wrapper Classes? Give any two examples.                                         [ISC 2018]
                   Ans. A Wrapper class in Java is a type of class that is used to convert primitive data types into objects and objects to primitive data
                       types. It wraps around a variable of one data type and converts it into an object. Thus, a wrapper class provides a way to use the
                       primitive data types (short, double, boolean, etc.) as objects in Java. Examples of two wrapper classes are:

                           S.No.      Primitive Data Type     Wrapper Class
                            1.      boolean               Boolean
                            2.      char                  Character
                   11.  A super class Number is defined to calculate the factorial of a number. Define a sub class Series to find the sum of the series
                       S = 1! + 2! + 3! + 4!+………......+n! The details of the members of both the classes are given below:    [ISC 2018]
                        Class name                        :   Number
                        Data Member/Instance variable
                        n                                 :   to store an integer number
                        Member Functions/Methods
                        Number(int nn)                    :   parameterized constructor to initialize the data member n=nn
                        int factorial (int a)             :   returns the factorial of a number (factorial of n = 1×2×3×………×n)
                        void display()                    :   displays the data members
                        Class name                        :   Series
                        Data Member/Instance variable
                        sum                               :   to store the sum of the series


                                                                                                                       491
                                                                                  Inheritance, Interfaces and Polymorphism  491
   488   489   490   491   492   493   494   495   496   497   498