Pages

Sunday, May 11, 2025

Static keyword : Static Object in OOPs

#include <iostream>
using namespace std;

class Example {
public:
    Example() {
        cout << "constructor..\n";
    }

    ~Example() {
        cout << "destructor..\n";
    }
};


int main() {
    int a = 0;
    if(a == 0) {
        static Example eg1;
    }

    cout << "code ending..\n";


    return 0;

} 


output:

constructor..

code ending..

destructor..

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...