this是可以调用静态方法及静态域的,但这种用法不好,容易让人误解,eclipse中会有warning: "The static field xxClass.xxVariable should be accessed in a static way" "静态域 某类.某域 应该以静态的方式访问"同时在静态方法中不能使用this关键字,eclipse中提示error: "Cannot use this in a static context" "不能在静态语境(就是静态的代码块)中使用this关键字"
如果是这样public void main(String [] args){ }没有static的话 类变量和类方法都能调用
/*
* 如果是静态方法了 this无法调用任何东西。
*/
public class Test {
static String name=new String("atr");
public void main(String [] args){
this.name=name;//类变量可以调用
this.println();//类方法可以调用
this.age;//成员变量无法调用
this.print();//成员方法可以调用
}
public void print(){
String age;
}
public static void println(){
}
}
* 如果是静态方法了 this无法调用任何东西。
*/
public class Test {
static String name=new String("atr");
public void CC(String name){
this.name=name;//类变量可以调用
this.println();//类方法可以调用
this.print();//成员方法可以调用
}
public void print(){
String age;
}
public static void println(){
}
"我书上说this不能调用类变量和类方法"这句话是从哪本书看的?我怎么觉得有问题啊,this可以调用(本)类变量和类方法的;不过一般也不会这样调用的,你要调用本类的类变量和类方法,不需要写this关键字,写上了反而多余。你的后半部分,话乱,话中要不没主语 要不没宾语,看不懂。
如果你写了一个静态方法,则这个静态方法在类运行时,在内存中独占一块,它部属于任何特定的对象,它只属于当前类的..所以说在静态方法中使用this是 错误的,因为它只局限于具体的类的对象
用static修饰的变量、方法是类变量、类方法,不能用this关键字调用。
"The static field xxClass.xxVariable should be accessed in a static way"
"静态域 某类.某域 应该以静态的方式访问"同时在静态方法中不能使用this关键字,eclipse中提示error:
"Cannot use this in a static context"
"不能在静态语境(就是静态的代码块)中使用this关键字"
this表示为当前类的对象,this不可以调用局部变量。