본문 바로가기

웹 프로그래밍/Spring Framework

[JAVA]객체 테스트 용 예제

package test;
import java.util.Scanner;

class Aircon {
 String company;
 String color;
 int price;
 int size;
 int temp;
 
 void powerOn(){
  System.out.println("Power On!");
 }
 void powerOff(){
  System.out.println("Power Off!");
 }
 
 void tempUp(){
  temp++;
 }
 void tempDown(){
  temp--;
 }
}
public class test {
 public static void main(String[] args) throws Exception {
  Aircon airCon = new Aircon();
  airCon.color = "White";
  airCon.temp = 10;
  airCon.price = 10000;
  airCon.tempUp();
  System.out.println("airCon.temp = " + airCon.temp + ", airCon.color = " + airCon.color + ", airCon.price = " + airCon.price);
  airCon.powerOn();
  airCon.powerOff();
  airCon.tempDown();
  System.out.println("airCon.temp = " + airCon.temp + ", airCon.color = " + airCon.color + ", airCon.price = " + airCon.price);
  Aircon airCon2 = new Aircon();
  airCon2.temp = 10;
  airCon2 = airCon; //객체(인스턴스) airCon 저장된 레퍼런스값을 airCon2 에 저장
  System.out.println("airCon.temp = " + airCon.temp + ", airCon.color = " + airCon.color + ", airCon.price = " + airCon.price);
 }
}

 

 

머 대충 이렇다 ㅎㅎ