Your SlideShare is downloading. ×
  • Like
What is inheritance
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply
Published

What is inheritance

What is inheritance

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
243
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 2. WHAT IS INHERITANCE ASNA.C.A kunjulaloos@gmail.com www.facebook.com/userna me twitter.com/username in.linkedin.com/in/profilena me 9048331776
  • 3. What Is Inheritance? One of the most important concepts in object- oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.
  • 4. Types of Inheritance 1. Single Inheritance 2. Multilevel Inheritance 3. Multiple Inheritance 4. Hierarchical Inheritance 5. Hybrid Inheritance In Inheritance Upper Class whose code we are actually inheriting is known as the Base or Super Class and Class which uses the Code are known as Derived or Sub Class.
  • 5. 1) In Single Inheritance there is only one Super Class and Only one Sub Class Means they have one to one Communication between them
  • 6. program of Single Inheritance #include<iostream.h> #include<conio.h> class student { public: int rno; //float per; char name[20]; void getdata() { cout<<"Enter RollNo :- t"; cin>>rno; cout<<"Enter Name :- t"; cin>>name; } };
  • 7. class marks : public student { public: int m1,m2,m3,tot; float per; void getmarks() { getdata(); cout<<"Enter Marks 1 :- t"; cin>>m1; cout<<"Enter Marks 2 :- t"; cin>>m2; cout<<"Enter Marks 2 :- t"; cin>>m3; }
  • 8. void display() { getmarks(); cout<<"Roll Not t Name t Marks1 t marks2 t Marks3 t Total t Percentage"; cout<<rno<<"t"<<name<<"t"<<m1<<"t"<<m2<<"t"<<m3<<"t"<<to <<"t"<<per; } }; void main() { student std; clrscr(); std.getmarks(); std.display(); getch(); }
  • 9. 2) In Multilevel Inheritance a Derived class can also inherited by another class Means in this When a Derived Class again will be inherited by another Class then it creates a Multiple Levels.
  • 10. Program of Multilevel Inheritance #include <iostream> using namespace std; class A { public: void display() { cout<<"Base class content."; } }; class B : public A { }; class C : public B { };
  • 11. int main() { C c; c.display(); return 0; }-
  • 12. 3) Multiple Inheritances is that in which a Class inherits the features from two Base Classes When a Derived Class takes Features from two Base Classes.
  • 13. Program of Multiple Inheritance #include<iostream.h> #include<conio.h> class student { protected: int rno,m1,m2; public: void get() { cout<<"Enter the Roll no :"; cin>>rno; cout<<"Enter the two marks :"; cin>>m1>>m2; } };
  • 14. class sports { protected: int sm; // sm = Sports mark public: void getsm() { cout<<"nEnter the sports mark :"; cin>>sm; } }; class statement:public student,public sports { int tot,avg; public: void display() {
  • 15. tot=(m1+m2+sm); avg=tot/3; cout<<"nntRoll No :"<<rno<<"ntTotal :"<<tot; cout<<"ntAverage : "<<avg; } }; void main() { clrscr(); statement obj; obj.get(); obj.getsm(); obj.display(); getch(); }
  • 16. 4) Hierarchical Inheritance is that in which a Base Class has Many Sub Classes or When a Base Class is used or inherited by many Sub Classes.
  • 17. #include <iostream.h> class Side { protected: int l; public: void set_values (int x) { l=x;} }; class Square: public Side { public: int sq() { return (l *l);
  • 18. } }; class Cube:public Side { public: int cub() { return (l *l*l); } }; int main () { Square s; s.set_values (10); cout << "The square value is::" << s.sq() << endl; Cube c; c.set_values (20); cout << "The cube value is::" << c.cub() << endl; return 0; }
  • 19. 5) Hybrid Inheritance: - This is a Mixture of two or More Inheritance and in this Inheritance a Code May Contains two or Three types of inheritance in Single Code.
  • 20. #include <iostream.h> class mm { protected: int rollno; public: void get_num(int a) { rollno = a; } void put_num() { cout << "Roll Number Is:"<< rollno << "n"; } }; class marks : public mm { protected: int sub1; nt sub2; public:
  • 21. void get_marks(int x,int y) { sub1 = x; sub2 = y; } void put_marks(void) { cout << "Subject 1:" << sub1 << "n"; cout << "Subject 2:" << sub2 << "n"; } }; class extra { protected: float e;
  • 22. public: void get_extra(float s) {e=s;} void put_extra(void) { cout << "Extra Score::" << e << "n"; } }; class res : public marks, public extra{ protected: float tot; public: void disp(void) {
  • 23. tot = sub1+sub2+e; put_num(); put_marks(); put_extra(); cout << "Total:"<< tot; } }; int main() { res std1; std1.get_num(10); std1.get_marks(10,20); std1.get_extra(33.12); std1.disp(); return 0; }
  • 24. THANKS
  • 25. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 26. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com