What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
A(){
a = 0;
}
void show(){
a++;
cout<<"a: "<<a<<endl;
}
};
class B: private A
{
public:
};
int main(int argc, char const *argv[])
{
B b;
b.show();
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
float d;
public:
int a;
void change(int i){
a = i;
}
void value_of_a(){
cout<<a;
}
};
class B: public A
{
int a = 15;
public:
void print(){
cout<<a;
}
};
int main(int argc, char const *argv[])
{
B b;
b.change(10);
b.print();
b.value_of_a();
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
float d;
public:
virtual void func(){
cout<<"Hello this is class A\n";
}
};
class B: public A
{
int a = 15;
public:
void func(){
cout<<"Hello this is class B\n";
}
};
int main(int argc, char const *argv[])
{
A *a = new A();
B b;
a = &b;
a->func();
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A{
float d;
public:
virtual void func(){
cout<<"Hello this is class A\n";
}
};
class B: public A{
int a = 15;
public:
void func(){
cout<<"Hello this is class B\n";
}
};
int main(int argc, char const *argv[])
{
B b;
b.func();
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class Mammal
{
public:
virtual void Define(){
cout<<"I'm a Mammal\n";
}
};
class Human: public Mammal
{
public:
void Define(){
cout<<"I'm a Human\n";
}
};
class Male: public Human
{
public:
void Define(){
cout<<"I'm a Male\n";
}
};
class Female: public Human
{
public:
void Define(){
cout<<"I'm a Female\n";
}
};
int main(int argc, char const *argv[])
{
Mammal *M;
Male m;
Female f;
*M = m;
M->Define();
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
int a, b;
float d;
public:
void change(int i){
a = i;
}
void value_of_a(){
cout<<a;
}
};
class B: private A
{
};
int main(int argc, char const *argv[])
{
B b;
cout<<sizeof(B);
return 0;
}