类对象中的
public:
string name;
protected:
string Car;
private:
string Password;
#include<iostream>
using namespace std;
class Base
{
public:
void head()
{
cout << "这是头部 " << endl;
}
void footer()
{
cout << "这是底部 " << endl;
}
void left()
{
cout << "这是左部 " << endl;
}
};
class JAVA :public Base
{
public:
void center()
{
cout << "这是java的中心 " << endl;
}
};
class Python :public Base
{
public:
void center()
{
cout << "这是python的中心 " << endl;
}
};
class CPP :public Base
{
public:
void center()
{
cout << "这是C++的中心 " << endl;
}
};
void text01(){
Python py;
py.head();
py.footer();
py.left();
py.center();
cout << "-----------------" << endl;
JAVA ja;
ja.head();
ja.footer();
ja.left();
ja.center();
cout << "-----------------" << endl;
CPP cpp;
cpp.head();
cpp.footer();
cpp.left();
cpp.center();
}
int main()
{
text01();
system("pause");
return 0;
}
#include<iostream>
using namespace std;
class Father
{
public:
Father()
{
m_A = 100;
}
void func()
{
cout << "父类函数的调用" << endl;
}
int m_A;
};
class son :public Father
{
public:
son()
{
m_A = 200;
}
void func()
{
cout << "子类函数的调用" << endl;
}
int m_A;
};
int main()
{
son son1;
son1.func();
son1.Father::func();
cout << son1.m_A << endl;
cout << son1.Father::m_A << endl;
system("pause");
return 1;
}
#include<iostream>
using namespace std;
class Base
{
public:
static void func()
{
cout << "Base 中function的调用" << endl;
}
static int m_A;
};
int Base::m_A = 100;
class Son :public Base
{
public:
static void func()
{
cout << "Son 中function的调用" << endl;
}
static int m_A;
};
int Son::m_A = 200;
int main()
{
Son s;
s.func();
cout << s.Base::m_A << endl;
cout << Son::m_A << endl;
Son::func();
Son::Base::func();
system("pause");
return 1;
}
|