调用这个Java方法的是什么?
好的,我是Java新手,有一个简短的问题要问任何愿意回答的人 此剂量测量方法调用的对象是什么?这和叫这个一样吗,doSomething调用这个Java方法的是什么?,java,Java,好的,我是Java新手,有一个简短的问题要问任何愿意回答的人 此剂量测量方法调用的对象是什么?这和叫这个一样吗,doSomething public class Something{ public void doSomething(){ System.out.println("Something is done"); } public Something(){ //what object is this being called on?
public class Something{
public void doSomething(){
System.out.println("Something is done");
}
public Something(){
//what object is this being called on?
doSomething();
}
public static void main(String[] args){
Something foo = new Something();
}
}
感谢您的帮助
这个被调用的对象是什么
将要分配给foo的引用,在构造函数的作用域中,它是this引用。是的,做点什么;在这种情况下相当于这个
我们可以通过向某物添加UUID并在doSomething中显示它来了解情况
然后再打电话给doSomething
您将获得两次相同的UUID。是的,doSomething是在Something类中定义的。因此,这与此相同。doSomething
要从类外调用Something类内声明的doSomething,您需要这样调用它:
public static void main(String[] args){
Something foo = new Something();
foo.doSomething();
}
对。调用this.doSomething与调用doSomething相同。不确定正在使用什么GUI。例如,如果您使用Eclipse并拥有以下代码,然后单击doSomething,它将带您进入void doSomething方法。使用它只是对当前实例的引用。关于这一点,可以找到更多细节 对查看有关的更多详细信息
public static void main(String[] args) {
Something foo = new Something();
foo.doSomething();
}
public static void main(String[] args){
Something foo = new Something();
foo.doSomething();
}
public class Something{
public void doSomething(){
System.out.println("Something is done");
}
public Something(){
//what object is this being called on?
this.doSomething();
}
public static void main(String[] args){
Something foo = new Something();
}
}