Pages

Saturday, May 10, 2025

Single 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(); // single inheritance , simplest inheritance
        cout << "swims..\n";
    }
};


int main() {
    Fish f1;

    f1.swim();
    f1.eat();
    f1.breathe();

    return 0;
}

No comments:

Post a Comment

Encode and Decode Strings - NeetCode.IO Solution by me + gemini pro 3.0 explained

  class Solution {         // encode: List of Strings -> String     public String encode ( List < String > strs) {         Stri...