【发布时间】:2015-02-16 12:02:04
【问题描述】:
大家好,我有一个问题。尝试将对象数组传递给方法时出现错误 我的课
public class Object {
private int x1;
public Object(int a ,){
this.x1=a;
}
public class staticMethods{
public static void findMaxPos(Object[] name){
max = name[0]
pos = 0
for( int i=1; i<name.length ; i++){
if ( name[i] >max ){
max = name[i];
pos = i;
}
}
}
public class Example{
public static void main(String[] args) {
Object[] yp = new Object2[3];
yp[0] = new Object(5);
yp[1] = new Object(6);
yp[2] = new Object(8);
findMaxPos(type)// i get an error of the method findMaxPos is undefined for the type Example
}
很抱歉这么长的帖子...
【问题讨论】:
-
你需要做
staticMethods.findMaxPos -
这些类在同一个文件夹中的不同文件中,我忘了提及它
-
好吧,开始你的代码甚至没有编译,例如
public Object(int a ,)是不完整的。此外,拥有一个名为 Object 的类可能是一个非常糟糕的主意,因为它也是 Java 类层次结构根部的类的名称。阅读代码时可能会变得非常混乱。 -
是的,伙计,对不起,我刚刚输入的速度非常快,它不是我的实际代码,我只编译它的逻辑......我需要输入 staticMethods.findMaxPos 作为 NG。声明..谢谢大家..将不得不对静态方法进行修订! :)
标签: java arrays object methods arguments