본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

TV 클래스

TV CLASS 생성


 

class tv {
 int channel;
 int volume;
 boolean power;
 void setPower(){
  power = !power;
 }
 void channelUp(){
  channel++;
 }
 void channelDown(){
  channel--;
 }
 void volumeUp(){
  volume += 2;
 }
 void volumeDown(){
  volume -= 3;
 }
}

public class TvTest{
 public static void main(String[] args){
   tv t = new tv();
   t.channel = 2;
   t.volume = 0;
   t.power = true;
  
   t.volumeUp();
   t.channelUp();
   System.out.println("현재 볼륨 : "+t.volume);
   System.out.println("현재 채널 : "+t.channel);
   System.out.println("현재 파워 : "+t.power);   
 }
}

 

 

 

TvTest.java

 

분리할 경우

 

Tv.java

 

TvTest.java