为什么这些方法显示错误 [英] Why these method showing an error

查看:55
本文介绍了为什么这些方法显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Medhod 1;

Medhod 1;

public class User {
    
 public void sample(String x,String y){

 }



方法2


Method 2

public class Test {
  String x,y;

    public void sample(x,y){
      
  }
     
}



i在第一种方法中创建了两种方法我传递的参数数据类型没有显示错误但是在第二种方法中首先我声明数据类型并传递它显示错误的变量

是什么原因?



我尝试过:



Medhod 1;


i created two methods in first method i pass arguments with data type it was not showing an error but in 2nd method first i declare data type and pass the variables it display an error
what is the reason ?

What I have tried:

Medhod 1;

public class User {
    
 public void sample(String x,String y){

 }





方法2



Method 2

public class Test {
  String x,y;

    public void sample(x,y){
      
  }
     
}

推荐答案

Quote:

公共类测试{

字符串x,y; //< - 这里你声明了班级的两个成员变量



public void sample(x,y){ //< - 这里你没有为方法形式参数提供类型

}

}

public class Test {
String x,y; //<- here your are declaring two member variables of the class

public void sample(x,y){ //<- here you are NOT providing types for the method formal parameters
}
}



注意 x,y 类成员变量完全未发布到示例方法形式参数 x,y

我认为你会受益于一个好的 Java tutorial。


Note the x,y class member variables are completely unreleated to the sample method formal parameters x,y.
I think you would benefit from a good Java tutorial.


这篇关于为什么这些方法显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆