안녕하세요, 저는 질문이 있습니다. 나는자바의 메소드에 객체 배열 전달하기
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'를 할 필요가 있습니다 –
클래스가 동일한 폴더에있는 다른 파일에 있습니다. 이것을 언급하는 것을 잊었습니다 – InFamouStarlight
글쎄, 코드를 컴파일하기도하지 않습니다. 예를 들어'public Object (int a,)'이 불완전합니다. 또한 Java 클래스 계층의 루트에있는 클래스의 이름이기 때문에 Object라는 클래스를 갖는 것이 실제로는 매우 나쁜 생각 일 수 있습니다. 코드를 읽을 때 정말 혼란 스러울 수 있습니다. –