重载相同 class Java

Overloading in same class Java

我现在正在尝试理解重载,但有点困惑。我知道调用同一个方法时,它不能有完全相同的参数。例如,一个方法调用了 2 个 int 变量,然后另一个方法调用了两个不同的 int 变量。但是如果我用一个int和一个float,那就没问题了。我知道 return 类型并不重要,但它是 public 或私有方法呢?这有关系吗?

例如,假设我打电话给 public int name(int x) 我能打电话给 private int name(int x) 吗?

我假设 public double name(String x) 也会导致 class 中的过载是否正确? public int name(int x, String y) 也有效吗?将字符串参数传递给 int 函数?这会导致过载或错误吗?

编辑:不要相信这个问题是重复的,我的主要问题是 public 和 private 之间的区别,它们是方法还是不同,会导致重载。没有看到其他问题中提到的问题。

来自Oracle tutorial

Overloaded methods are differentiated by the number and the type of the arguments passed into the method.

...

You cannot declare more than one method with the same name and the same number and type of arguments, because the compiler cannot tell them apart.

所以访问修饰符不算数。您不能同时拥有 public int name(int x)private int name(int x).

Am I correct in assuming public double name(String x) would also cause overloading in the class?

是的,因为它具有相同的名称但参数类型不同。

Also is public int name(int x, String y) valid? Passing a string argument into an int function? Would this cause overloading or an error?

同样,由于方法名相同,参数类型不同,所以是重载方法