Top Post

6/recent/ticker-posts

CS304 LECTURE 23

 Constructor


CODE:

#include <iostream>
using namespace std;
class vubwn{
    public:
     vubwn(int a,int b){
         cout<<"Sum :"<<a+b<<endl;
     }
};
int main()
{
    vubwn obj(3,4);   
    return 0;
}


Accessing base class member functions in derived class:

#include <iostream>
using namespace std;
class A{
    public:
    int a,b;
    void sum(){
        cout<<"Sum :"<<a+b<<endl;
    }
};
int main()
{
    A obj;
    obj.a=2;
    obj.b=34;
    obj.sum();
    return 0;
}






















Post a Comment

0 Comments