반응형
자바에서는 Class 내에 Method를 선언하고 외부에서 Method를 Call할 수 있습니다.
프로그램
public class method_call {
static String myMethod() {
return "hello world 2";
}
public static void main(String[] args) {
System.out.println("hello world 1");
String text = myMethod();
System.out.print(text);
}
}
예상결과
hello world 1
hello world 2
풀이
1. 메소드를 call하면 문자 String을 되돌려주는 메소드 정의
static String myMethod() {
return "hello world 2";
}
2. 메인 Process가 메소드를 Call 하고 결과 String을 로컬 스트링으로 받음, 받은 스트링을 출력
String text = myMethod();
System.out.print(text);
728x90
'웹서버 프로그래밍 (node.js) > 자바 프로그래밍' 카테고리의 다른 글
자바 시간 delay (0) | 2020.03.02 |
---|---|
자바 Class 외부 Method 선언 및 외부 Method Call (0) | 2020.03.02 |
자바 hello world (0) | 2020.03.02 |
자바 , 이클립스 설치 (0) | 2020.02.28 |