#include<iostream>
using namespace std;
class People{
private:
string name;
int id;
protected:
int age;
void hehe(){
cout << "hehe" << endl;
}
public:
People(){name="NULL";id=-1;}
People(string nm,int i):name(nm),id(i){}
void shout(){
cout << "Aiyooooo... I'm " << name <<'\t' << endl;
hehe();
}
void setId(int i){
id=i;
}
void setname(string n){name=n;}
string getname(){return name;}
};
class Student:public People{
private:
int sid;
// int score;
public:
Student(){
People();
sid=999;
}
Student(string nm,int i,int s)
:People (nm,i),sid(s){}
string getname(){return People::getname();}
void learn(){
cout <<sid<<endl;
}
void shout(){
cout << "Haha...I'm" <<getname() << endl;
}
};
int main(){
// People zs("Z",1001);
Student ls("Lisi",1001,999);
ls.learn();
ls.shout();
return 0;
}
C++简单继承
最新推荐文章于 2023-05-30 20:24:32 发布