이 시도 :
public class A {
int arrayA[] = {1,2,4,5,3}; //unsorted array
}
public class B extends A {
int arrayB[];
public void exampleOfCopySortPrint() {
arrayB = Arrays.copyOf(arrayA, 5); // copy the values of arrayA into arrayB
// arrayB is now an entirely new array
Arrays.sort(arrayB); // this sorts the array from small to large
// print all elements in arrayB
for (int i : arrayB) {
System.out.println(i); // 1, 2, 3, 4, 5 (sorted)
}
}
}
또한 클래스 B의 필드를 추가
당신이 protected int array[];
처럼 배열 필드에 수정 대중를 추가하거나 보호하지 않으면 필요가 없습니다 클래스 A에서 동일한 폴더/패키지에 2 개의 클래스를 배치해야합니다.
'배열'을 상속하지 않는 이유는 무엇입니까? –
배열을 상속하는 방법은 무엇입니까? – Jorvis
다른 방법으로 상속받는 것과 같습니다. –