目的:创建对象访问类的属性和方法
1.c++中实现
#include <iostream>
using namespace std; // 使用命名空间
/**
* 定义car类
*/
class car {
private:
int _wheels; //car属性1:车的轮子个数
int _speed; //car属性2:车的时速
public:
/**
* 轮子的set方法
*/
void setWheels(int wheels)
{
_wheels = wheels;
}
/**
* 车的时速的set方法
*/
void setSpeed(int speed)
{
_speed = speed;
}
/**
* 轮子的get方法
*/
int getWheels()
{
return _wheels;