Page 452 - Computer science 868 Class 12
P. 452

12.1.4 Visiblity Modes of Inheritance
              Visibility modes are used to implement the OOP concept of data hiding. It controls which members of the parent class
              can be accessible in the child (derived) class. The default visibility mode in Java is set to public.
              Visibility modes used in Java are:
              •   private: private members are accessible only inside their own class and are not inherited.
              •   protected: protected members are accessible inside their own class, classes within the package and subclasses.
              •   public: public members are accessible in all the classes within or outside the package.

              •   default: default members are accessible in all the classes within the package to which they belong. Data members
                 assume default mode when the visibility mode declaration is not given.

              The accessibility of the visibility modes in the same or different class or package is summarised in the table given below.

                                         Same class          Same package              Different package
                                                        Subclass    Non subclass    Subclass    Non subclass
                         public        Yes           Yes           Yes           Yes            Yes
                         default       Yes           Yes           Yes           No             No
                         protected     Yes           Yes           Yes           Yes            No
                         private       Yes           No            No            No             No


              12.1.5 Types of Inheritance                                                                      Base
              •  Single Inheritance: In single inheritance, a single subclass inherits the properties of a single base
                 class as illustrated in the diagram.
                                                                                                             Derived
                  Base1
                             •   Multilevel Inheritance: In this form of inheritance, a derived class can also be inherited by another
                Derived1/      class which means this derived class is the base class of a second derived class, thus, creating
                  Base2
                               multiple levels of relationship hierarchy as shown in the diagram.


                 Derived2

              •    Multiple  Inheritance:  In  multiple  inheritance,  a  derived  class   Base1  Base2        Base3
                 inherits the features from more than one base classes. The pictorial
                 representation is shown alongside.
                                                                                               Derived



                450450  Touchpad Computer Science-XII
   447   448   449   450   451   452   453   454   455   456   457