본문 바로가기
Language/JAVA

JAVA 객체 (6) - a++ 연습문제

by 파2RI 2023. 7. 21.
package hakwon3;

class Plus{
    
	int a;
	
		int Plusone(int a) {
			
			a++;		
			return a;  // 꼭 return a를 해줘야 a++된 값이 출력된다!
			
	}
	
}


public class Practice {

	public static void main(String[] args) {
		
		Plus firstsample = new Plus();
		int firstresult = firstsample.Plusone(31);
		Plus secondsample = new Plus();
		int secondresult = secondsample.Plusone(88);
		
		System.out.println(firstresult);
		System.out.println(secondresult);
		
		}
		
	}

 

32
89