关于C++/JAVA类中的static成员和对象成员的说法正确的是:
来源:互联网 发布:天猫魔盒软件官方网站 编辑:程序博客网 时间:2024/04/30 06:00
A:static成员变量在对象构造时候生成
B: static成员函数在对象成员函数中无法调用
C: 虚成员函数不可能是static成员函数
D: static成员函数不能访问static成员变量
答案:c 解释,(1)类的static成员变量属于该抽象类,需要在类定义时初始化,不可以在对象的构造函数中初始化。(2) static成员函数在对象成员函数中可以调用,同属于一个类作用域 (3)正确,static成员函数不可以声明为const和virtual,详见C++ primer (4)static成员函数只能够访问static 成员变量。
#ifndef TEST_H
#define TEST_H
#include <stdio.h>
class test
{
private:
int submember;
static int member;
public:
static void writetest(int member)
{
test::member = member;
// test::submember = member;
}
static void display(int count)//static成员函数,属于抽象类,不属于类对象
{
printf("the count number is %d \n",count);
}
void readtest(int mem) //对象成员函数
{
printf("helllo %d \n",test::submember);
// test::writetest(mem);// static成员函数在对象成员函数中可以调用,同属于一个类作用域,但是,static函数不能包含对stati成员的操作,否则出现错误
display(8);
}
};
#endif
#include "onceon.h"
int main(void)
{
int aa = 2;
test a ;
a.readtest(aa);
}
- 关于C++/JAVA类中的static成员和对象成员的说法正确的是:
- 关于C++/JAVA类中的static成员和对象成员的说法正确的是:
- c++中的static关键字(和python的类成员和对象成员类似)
- c++-类的static成员
- 【C/C++】类中的static成员、static const成员和const成员
- 关于STP、RSTP 和MSTP 说法正确的是
- 关于java static成员的学习
- 关于static修饰一个类中的成员函数的问题
- Java面向对象-类成员和实例成员的访问
- C++中的static成员、static const成员和const成员的初始化
- const static与类的数据成员,成员函数,对象
- 关于C++中类的static和const成员
- C++ 类中的static成员的初始化和特点
- 详解C++类的静态成员和C语言中的static
- 类的static成员
- 类的static成员
- 类的static成员
- c/c++ 类的static成员
- Flash Builder4.7 破解方法的实践
- Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block
- POJ 2155 - Matrix 二维树状数组..区间更新..单点查询
- ubuntu12.04本地搭建ubuntu更新源
- HSU 4536 XCOM Enemy Unknown && 2013腾讯编程马拉松复赛第二场
- 关于C++/JAVA类中的static成员和对象成员的说法正确的是:
- 变参函数——stdarg——printf——variable and function
- Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception
- JavaScript收藏~From 脚本之家
- 欧几里德算法--求最大公约数
- Microsoft Enterprise Library 5.0 系列教程(九) Policy Injection Application Block
- 微软云技术Windows Azure专题(四):如何利用Mobile Service的计划程序连接到Service Bus定时推送消息
- hibernate映射文件
- PRML Chapter 9.2 Mixtures of Gaussians 混合高斯分布简介