private什么意思
private什么意思
答案:1 悬赏:50 手机版
解决时间 2021-05-21 16:43
- 提问者网友:鼻尖触碰
- 2021-05-21 11:34
最佳答案
- 五星知识达人网友:往事隔山水
- 2021-05-21 13:10
private 是C++的关键字,表示私有成员.
private 是类中的一个属性 用它定义的feild和method只能在类中被调用.如果定义了private,就不能被外部类所访问了
比如说你在一个类中有这样的定义:
class test{
private int n;
private int m;
}
然后你想在另一个地方调用n和m.
class text{
public static void main(String [] arg){
test x=new test();
int s=x.n;
}
}
就会产生错误.
你可以在定义test类的时候加上一定的方法来返回n和m的值.
public int getn(){return n;}
public int getm(){return m;}
然后在调用的时候
s=x.getn();
就可以了!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯