in C++ and Java, if you have (pseudo code)
class A
{
int x;
static void method(){...}
void anotherMethod(){...}
}you can access method() through an A's instance like this
A a = ....;
a.method();But you cannot do this in C#, you have to use A.method()if anotherMethod() has to use the member variable "x" directly, then anotherMethod() cannot be a static method, since a static method does not have an implicit "this" parameter passed in
class A
{
int x;
static void method(){...}
void anotherMethod(){...}
}you can access method() through an A's instance like this
A a = ....;
a.method();But you cannot do this in C#, you have to use A.method()if anotherMethod() has to use the member variable "x" directly, then anotherMethod() cannot be a static method, since a static method does not have an implicit "this" parameter passed in
解决方案 »
- 我毕业后做的是IBM大型机软件开发,做了半年,觉得没啥意思,都是维护,或是些很简单的开发
- 【急】 netbeans 6.1 中单击按钮关闭窗口问题
- 小白问题:啥叫图形上下文
- 有没有遇到过catch 中没有捕获,而throw却能现实的异常?
- 怎样规范而且清晰的定义一个类?
- Eclipse的plug-in
- 哪位高手有解密的Optimizeit Suite 5下载?
- 有关update方法的使用(在线等待)
- 请高手说说,你们学习的Java的经验
- java 数据采集
- 菜鸟请教:我下了一个freeJava,怎么编译程序(程序没问题)没反应,它的JDk目录我也设了d:\jdk.3(JDK1.3不是安装的,是从JBuilder5直接里复制放在d:\jdk1.3里),用别的工具都可以编译成功!
- 关于j2sdkee的deploytool的初级问题,请指教!
本意应该是一个类的非静态方法不能用通常(使用this指针)的方法访问这个类定义的静态成员。在这一点上java和c++是一样的。
2.在JAVA中只有静态方法可以访问静态变量。