: is the process of creating a new class(derived classes) from existing classes( ase lasses). The derived classes not only inherit the capabilities of the base class abut also can add new features of their own. The process of inheritance does not affect the base class. The most important features of inheritance is that it allows reusability of code, and also a debugged class can be used to work in different situations. Reusability of code saves money as well as time and increase program reliability. is very useful in original conceptualization and design of a programming problem. Single level Multi Level Hierarchical Types of inheritance Multiple Hybrid D Visibility Under Different Modes Member Object Member Member Object Object ly Derived
ly Derived Derived las Single class lassname Derived SYNT Single Level class <Derived class name>:<ccess specifier> < Name> Example of single Level ountry State lass ountry class state :public country int no_of_farms; void Get( ); void Put ( );
class lassname Multi Level class <Derived class name>:<ccess specifier> < Name> SYNT Multi Level ountry State District class <Devied class Name> :<ccess Specifier> < Name> <lass Member >; <lass member>; <lass member>; Example of Multi Level lass ountry class state :public country int no_of_farms; void Get( ); void Put ( ); class District : public state int no_of_offices; void input( ); void output( );
class lassname class lassname Multiple SYNT Multiple class < Name>:<ccess Specifier>< Name>, <ccess Specifier> < Name> <lass Member>; <class Member>; ountry Rules Example of multiple lass ountry 1 class Givernment int articleno; 2 void Get( ); void Put( ); lass Rules: public ountry, public Government char description[80]; void input( ); void output( ); } Government
class lassname Hierarchical lass < Name1>:<ccess Specifier>< Name> Syntax Hierarchical lass < Name2>:<ccess Specifier>< Name> ountry Example of Hierarchical class ountry class state :public country int no_of_farms; void Get( ); void Put ( ); State Union Territory class UnionTerritory : public ountry int no_of_offices; void Input( ); void Output( );
Q1. nswer the question with the help of the portion of program shown below class U int u; int y; void haveit( ); void showit(); class T : public U int x1; void calc ( ); int y1; void doit( ); int z1; void ShowIt(); void ddit( ); class P: private T int x2; int y2; int z2; void Display(); void hange( ); a) Name the member function(s), which can be accessed from the object of, class P. b) Name the data member(s), which can be accessed from the member function of class T. c) Name the data member(s), which can be accessed from the object of class U. d) is the data member Y declared in class U accessible to the member function hange( ) of class P. e) How many bytes will be required by an object of class P. f) Write the definition of member function display ( ) of class P to display all data members which are accessible from it. g) Write the name of base class and derived class of class T. h) Name the inheritance shown in this example.
Object Oriented Programming & Procedural Programming Object Oriented Programming Procedural Programming Emphasis on data Emphasis on doing things( function) Follows bottom-up approach in program design Follow top down approach in program design oncept of data Hiding prevents accidental change Due to presence of global variables, there is a in the data possibility of accidental change in data Polymorphism,, Data Encapsulation Not pplicable possible Data Encapsulation: Wrapping up of data and function in a single unit is known as data encapsulation. In a class, we encapsulate the data and function together in a single unit. Data Hiding : Keeping the data in private/ visibility mode of a class to prevent it from accidental modification ( hange) is known as data Hiding dditional Definition Run Time Error : run time error occurs during the execution of the program, when the program perform an illegal /unexpected operation For example ( Division by Zero) = U*H-P; y = Z/ ; // will be run time error if becomes zero from the first statement Syntax Error : syntax error occurs when the compiler is unable to translate the program to machine language due to violation of rules of the programming language. For example ( in ++, if statement is not enclosed in brackets) if x> 90 cout<< \n Value of x is 90 ; Logical Error : logical error occurs when the program contains wrong formula or wrong manipulation, which may me syntactically correct. The program having logical error may give some output but not the expected one. For Example // int sum; float average;../., verage = sum /5;