Page 486 - Computer science 868 Class 12
P. 486

Previous Years' Questions



                  1.  The keyword that allows multi-level inheritance in Java programming is:                  [ISC 2023]
                    (a)   implements                            (b)   super
                    (c)   extends                               (d)   this
                Ans. (c) extends
                     Explanation: Using extends keyword, a class we can achieve multilevel inheritance
                  2. Mention any two properties of the data members of an Interface.                           [ISC 2023]
                Ans. Two properties of the data members of an Interface are:-
                     (a)  The data members are public, static final by default.
                     (b)  Data members of an Interface cannot be changed in the due course of the program.
                  3. A super class Demand has been defined to store the details of the demands for a product. Define a subclass Supply which
                    contains the production and supply details of the products.5
                    The details of the members of both the classes are given below:                            [ISC 2023]
                    Class name                            :   Demand
                    Data members/instance variable:
                    pid                                   :   string to store the product ID
                    pname                                 :   string to store the product name
                    pdemand                               :   integer to store the quantity demanded for the product
                    Methods/Member functions:
                    Demand(...)                           :   parameterised constructor to assign values to the data members
                    void display()                        :   to display the details of the product
                    Class name                            :   Supply
                    Data members/instance variables:
                    pproduced                             :   integer to store the quantity of the product produced
                    prate                                 :   to store the cost per unit of the product in decimal
                    Methods/Member function:
                    Supply(...)                           :    parameterised constructor to assign values to the data members of both
                                                            the classes
                    double calculation()                  :    returns the difference between the amount of demand (rate × demand) and
                                                            the amount produced (rate × produced)
                    void display()                        :    to display the details of the product and the difference in amount of demand
                                                            and amount of supply by invoking the method calculation()
                     Assume that the super class Demand has been defined. Using the concept to inheritance, specify the class Supply giving the
                    details of the constructor(...), double calculation() and void display(). The super class, main function and algorithm need NOT be
                    written.

                Ans. class Supply extends Demand
                    {
                    int pproduced;
                    double prate;
                    public Supply(String a, String b, int c, int d, double e)
                    {
                    super(a,b,c);
                    produced=d;
                    prate=e;
                    }
                    public double calculation( )
                    {
                    return Math.abs(prate*pdemand - prate*pproduce);
                    }
                    public void display( )
                    {



                484484  Touchpad Computer Science-XII
   481   482   483   484   485   486   487   488   489   490   491