[Java] non-static method UnionParent(int[],int,int) cannot be referenced from a static context

Halo·2025년 5월 19일

Error

목록 보기
2/5
post-thumbnail

⚠️ 에러

non-static method UnionParent(int[],int,int) cannot be referenced from a static context


👀 원인

각 메서드는 다른 메모리에 선언됨으로 인한 호출 불가가 원인이였다.

메서드 생성 위치

  • static : 정적 메모리
  • non-static : 스택

위와 같이 keword 별로 서로 다른 메모리에 할당되므로 같은 메모리 안에서 생성될 수 있게 해줘야한다.


👍🏻 해결

public static void UnionParent(int[] parent, int a, int b) {

불러오고자 하는 함수에 static을 붙여주었다.

profile
새끼 고양이 키우고 싶다

0개의 댓글