Pages

Sunday, May 11, 2025

Hierarchical Inheritance in OOPs

 #include <iostream>

using namespace std;
// hierarchical inheritance

class Animal {
public:
    string eat;
    string breathe;
};

class Bird : public Animal {
public:
    string fly;
};

class Fish : public Animal {
public:
    string swim;
};

class Mammal : public Animal {
public:
    string walk;
};


int main() {
    Bird b1;
    Fish f1;
    Mammal m1;

    b1.fly = "bird flies..";
    f1.swim = "fish swims..";
    m1.walk = "mammal walks..";


    cout << b1.fly << endl;
    cout << f1.swim << endl;
    cout << m1.walk << endl;

    return 0;
}

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...