다섯 번째, 마지막 메서드인 method5를 실행하겠습니다. method5는 정수인 y 값을 받아서 리턴합니다.
public int method5(int y) { System.out.println(y + "이용한 m5 실행"); return y*2; }
앞에서 사용한 대로 리턴한 값을 int형 변수에 받아서 출력하겠습니다.
package javaStudy;
public class MyClassExam {
public static void main(String[] args) {
MyClass myclass = new MyClass();
myclass.method1();
myclass.method2(10);
int value = myclass.method3();
System.out.println("m3가 리턴한 값"+ value);
myclass.method4(5, 10);
int value2 = myclass.method5(55);
System.out.println("m5가 리턴한 값: "+ value2);
}
}