//constructor in inheritance #include <iostream.h> #include <conio.h> #include <string.h> class parent { int no; public: parent(int n) { no = n; } void dsply() { cout << "No is : " << no << endl; } }; class child : public parent { char str[10]; public: child(int n, char st[]) : parent(n) ...
Posts
Showing posts with the label inheritance in cpp
- Get link
- X
- Other Apps
/* Multiple Inheritance B C | | ----A---- */ #include <iostream.h> #include <conio.h> class B { public: int b; }; class C { public : int c; }; class A : public B, public C { public : int a; }; void main() { clrscr(); A obj; obj.a = 10; obj.b = 20; obj.c = 30; cout << endl << obj.a; cout << endl << obj.b; cout << endl << obj.c; getch(); }
- Get link
- X
- Other Apps
// Hybrid inheritance /* A | B __|__ | | C D */ #include <iostream.h> #include <conio.h> class A { public: int a; }; class B : public A { public: int b; }; class C : public B { public: int c; }; class D : public B { public: int d; }; void main() { clrscr(); C obj; D obj1; obj.a = 10; obj.b = 20; obj.c = 30; obj1.a = 200; ...
- Get link
- X
- Other Apps
/* Hybrid inheritance A B |_____| | C | D */ #include <iostream.h> #include <conio.h> class A { public: void showA() { cout << "class A -> showA() function called" << endl; } }; class B { public: void showB() { cout << "class B -> showB() function called" << endl; } }; class C : public B, public A { public: void showC() ...
- Get link
- X
- Other Apps
/*Hybrid Inheritance (virtual base classA) ____A____ | | | B---D---C */ #include <iostream.h> #include <conio.h> class A { public: void printA() { cout << "Class A -> printA function called" << endl; } }; class B :virtual public A { public: void printB() { cout << "Class B -> printB function called" << endl; } }; class C : virtual public A { public: void printC() ...
- Get link
- X
- Other Apps
//Multiple inheritance #include <iostream.h> #include <conio.h> class student { int a; char name[10]; public: void getdata() { cout << "Enter name : "; cin.getline(name, 10); cout << "Enter roll no : "; cin >> a; } void display() { cout << endl << "Name is : " << name; cout << endl << "Roll no is :" << a; ...
- Get link
- X
- Other Apps
/* Multilevel Inhetritance b c | | ----- | A */ #include <iostream.h> #include <conio.h> class B { public: void showB() { cout << "class B -> showB function called " << endl; } }; class C { public: void showC() { cout << "class C -> showC function called " << endl; } }; class A : public B, public C { public: void showA() { ...
- Get link
- X
- Other Apps
//Multilevel inheritance // A -> B -> C #include <iostream.h> #include <conio.h> class A { protected: void showA() { cout << endl << "class A -> showA function called"; } }; class B : public A { protected: void showB() { cout << endl << "class B -> showB function called"; } }; class C : B { protected: void showC() { cout << endl << "class C -> showC function called"; ...
- Get link
- X
- Other Apps
//multilevel inheritance // A -> B -> C #include <iostream.h> #include <conio.h> class A { public: void showA() { cout << endl << "class A -> showA function called"; } }; class B : public A { public: void showB() { cout << endl << "class B -> showB function called"; } }; class C : public B { public: void showC() { cout << endl << "class C -> showC function called"; ...
- Get link
- X
- Other Apps
// protectedly inherited #include <iostream.h> #include <conio.h> class super { public: void print() { cout << "super class -> print function called"; } }; class sub : protected super { public: void show() { print(); cout << endl << "sub class -> print function called "; } }; void main() { clrscr(); sub obj; obj.show(); getch(); }
- Get link
- X
- Other Apps
//inheritance // priverly inherited #include <iostream.h> #include <conio.h> class base { public: void show() { cout << "Base class -> show function called"; } }; class derived : private base { public: void print() { show(); cout << endl << "Derived class -> Print function called"; } }; void main() { clrscr(); derived obj; obj.print(); getch(); }
- Get link
- X
- Other Apps
//inheritance // priverly inherited #include <iostream.h> #include <conio.h> class base { public: void show() { cout << "Base class -> show function called"; } }; class derived : private base { public: void print() { show(); cout << endl << "Derived class -> Print function called"; } }; void main() { clrscr(); derived obj; obj.print(); getch(); }