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
解决方案 »
- 求高手指点hello world为什么死活不出现?只有手机摸拟器界面
- Java实现POS打印机无驱打印
- 下边这个代码为什么不抛异常?
- String对象问题
- 在Eclipse中使用Ant的时候,怎么设置系统环境变量
- JSP怎么学啊?
- 为什么我按回车没有反应?
- 请多指教get connection from datasource fail : Cannot create JDBC driver of class '' for connect URL 'null'
- 这个错误怎么回事?
- 请问如何捕获JEditorPane上的事件?
- 菜鸟请教:我下了一个freeJava,怎么编译程序(程序没问题)没反应,它的JDk目录我也设了d:\jdk.3(JDK1.3不是安装的,是从JBuilder5直接里复制放在d:\jdk1.3里),用别的工具都可以编译成功!
- 关于j2sdkee的deploytool的初级问题,请指教!
本意应该是一个类的非静态方法不能用通常(使用this指针)的方法访问这个类定义的静态成员。在这一点上java和c++是一样的。
2.在JAVA中只有静态方法可以访问静态变量。