상세 컨텐츠

본문 제목

void / static 의미

JAVA/JAVA 기초

by yeongs 2020. 10. 1. 22:50

본문

void / static 의미

class Calc{

	public int add(int a, int b)

	{

	int c = a + b;

	return c;

	}
}

public class Test1 {

	public static int add(int a, int b) // a=x ,b=y

	{

		int c = a + b ; 

		System.out.println(c); 

		return c; // c를 출력		

		

	}

	public static void main(String[] args) // void return 타입 없음

	{

		int x = 1; 

		int y = 2;

		

		int k = Test1.add(x, y); // static 바로 사용 가능

		

		Calc c = new Calc();  //  따로 메모리 할당 해줘야함 

		int z = c.add(x,y);

		System.out.println(z);



	}



}

 

 

'JAVA > JAVA 기초' 카테고리의 다른 글

BufferedReader / BufferedWriter  (0) 2020.10.01
setter /getter 쉽게 만들기  (0) 2020.10.01
자바 홀수 또는 짝수만 출력 continue 활용  (0) 2020.10.01
반복문 퀴즈  (0) 2020.10.01
for 이중 / while for 구구단 만들기  (0) 2020.10.01

관련글 더보기

댓글 영역