Pages

Saturday, May 10, 2025

Mode of inheritance in OOPs

 #include <iostream>

using namespace std;

class Animal {
public:
    string color;
    void eat() {
        cout << "eats..\n";
    }

    void breathe() {
        cout << "breathes..\n";
    }

};


class Fish : public Animal {
public:
    int fins;
   
    void swim() {
        eat(); // access like this eat() , if protected
        cout << "swims..\n";
    }
};


int main() {
    Fish f1;

    // public inheritance
    f1.fins = 3;
    cout << f1.fins << endl;
    f1.swim();
    f1.eat();
    f1.breathe();

    return 0;
}

No comments:

Post a Comment

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...