62 lines
836 B
C++
62 lines
836 B
C++
#include <iostream>
|
|
using namespace std;
|
|
class A1 {
|
|
public:
|
|
A1() {
|
|
x = 2;
|
|
y = 2;
|
|
}
|
|
A1(int i) {
|
|
x = i;
|
|
y = 18;
|
|
}
|
|
A1(int i, int j) {
|
|
x = i;
|
|
y = j;
|
|
}
|
|
void display() {
|
|
cout << "x=" << x << " y=" << y;
|
|
}
|
|
|
|
private:
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
class A2 : public A1 {
|
|
public:
|
|
A2() {
|
|
z = 20;
|
|
}
|
|
A2(int i) : A1(i) {
|
|
z = 1;
|
|
}
|
|
A2(int i, int j) : A1(i + 1, j) {
|
|
z = 2;
|
|
}
|
|
A2(int i, int j, int k) : A1(i, j + 3) {
|
|
z = k;
|
|
}
|
|
void display1() {
|
|
display();
|
|
cout << "z=" << z << endl;
|
|
}
|
|
|
|
private:
|
|
int z;
|
|
};
|
|
|
|
int main() {
|
|
A1 b1(2, 3);
|
|
A2 b2(5);
|
|
A2 b3(3, 2, 1);
|
|
b1.display();
|
|
b2.display1();
|
|
b3.display1();
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
x=2 y=3x=5 y=18z=1
|
|
x=3 y=5z=1
|
|
*/ |