Page 465 - Cs_withBlue_J_C11_Flipbook
P. 465

C.  Answer the following questions:
                    1.  What is the difference between a class and a package.
                   Ans.                     Class                                         Package

                       A class is a blueprint or prototype of similar objects.  A package is a namespace under which you can categorise
                                                                      classes.

                    2.  Differentiate between package and import keyword.
                   Ans.                    Package                                        Import

                       Package is used to put all related modules into one   Import is used to include the specific class in a particular
                       common folder for a better understanding.      package that we need to run our application.

                    3.  Differentiate between public and default access in class.
                   Ans.                     Public                                        Default
                       Data members, member methods, and blocks declared   Data Members,  member  methods, and blocks declared
                       inside a public class can be accessed from any class.  inside a default class is available to any other class in the
                                                                      same package.
                       The access specifier public must be written.   The access specifier is not written.
                    4.  Differentiate between user-defined package and built-in package.
                   Ans.
                                       Built-in packages                            User-defined packages
                       The packages that are already defined in Java software are  The packages that are created by the programmer  are
                       known as built-in packages.                    known as user-defined packages.
                    5.  Differentiate  between JDK and API.
                   Ans.
                                             JDK                                            API
                       Java Development Kit is a software development   Java Application Programming Interface (API) gives us the
                       environment used for developing Java applications and   list of all the packages, classes, interfaces along with their
                       applets.                                       fields and methods.
                       It includes the Java Runtime Environment (JRE), an   It contains  classes and packages,  which  are  helpful  in
                       interpreter/loader (Java), a compiler (javac), an archiver   minimising and simplifying Java coding like java.lang, java.
                       (jar), a documentation generator (Javadoc) and API.   util, java.io, etc.
                    6.  Write a program to create a package Eleven containing class AreaC having the following specifications:
                        Package                         :     Eleven
                        Class name                      :     AreaC
                        Data Members
                        double radius                   :     Store radius of a circle
                        Member Methods
                        AreaC(double r)                 :     Constructor to assign the data members
                        double  calarea()               :     Calculates and returns the area of a circle using the formula A = πr
                                                                                                                  2
                        Write a second class Shape in package Orange_prog to import class AreaC of package Eleven and use the method calarea() to
                       calculate the volume of cone and cylinder. The class description is given below.
                        Package                         :     Orange_prog
                        Class name                      :     Shape
                        Data Members
                        double height, vol              :     Stores height and vol
                        Member Methods
                        void conevol()                    :   Accepts height and calculates the volume of a cone using the formula πr h/3
                                                                                                                      2
                                                                                                                      2
                        void cylindervol()              :     Accepts height and calculates the volume of a cylinder using the formula πr h
                   Ans.  package Eleven;
                       public class AreaC


                                                                                                                       463
                                                                                                            Packages   463
   460   461   462   463   464   465   466   467   468   469   470