Pages

Sunday, May 11, 2025

Pure Virtual Function in OOPs

 #include <iostream>

using namespace std;

// abstract class
class Shape {
public:
    virtual void draw() = 0; //abstract fnx, pure-virtual fnx
};

class Circle : public Shape {
public:
    void draw() {
        cout << "draw circle\n";
    }
};

class Square : public Shape {
public:
    void draw() {
        cout << "draw square\n";
    }
};

int main() {

    Circle c1;
    c1.draw();

    Square sq1;
    sq1.draw();


    return 0;
}

output:
draw circle
draw square

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...