Page 16 - Data Structures Interactive Book
P. 16

program.  By  using  classes  and  objects,  programmers  can  model  complex  systems  in  a

               structured way. For example, a Student class may contain attributes such as name and id,

               along  with  methods  to  display  or  process  student  information.  This  abstraction  makes
               programs easier to understand and extend.

                 Example:





































               1.2.2  Inheritance

                       Inheritance allows a new class (derived class) to acquire properties and behaviors from

               an  existing  class  (base  class).  This  mechanism  promotes  code  reuse  and  establishes

               hierarchical relationships between classes. For instance, a GraduateStudent class may inherit

               attributes  and  methods  from  a  general  Student  class  while  adding  specialized  features.
               Inheritance supports extensibility and reduces redundancy in program design.


               1.2.3  Polymorphism


                       Polymorphism  means  “many  forms”  and  allows  functions  or  methods  to  behave

               differently  depending  on  context.  In  C++,  polymorphism  is  achieved  through  function
               overloading and function overriding. Function overloading enables multiple functions with

               the same name but different parameter lists, while function overriding allows a derived class


                                                             16
   11   12   13   14   15   16   17   18   19   20   21