타닥타닥 개발자의 일상

Java 객체지향문( Object Oriented Programing) 의 특징 및 예제 본문

코딩 기록/Java

Java 객체지향문( Object Oriented Programing) 의 특징 및 예제

NomadHaven 2021. 12. 14. 23:13

 OOP ( Object Oriented Programing )
 프로그램의 구조, 관리때 쓰이는 기법
 객체 지향 프로그래밍

 특징
 1. 은닉성(캡슐화) 
 2. 상속성
 3. 다형성

 형식:
  class 명 {
  variable
 
  method
  } 
  

public class OOP {

public static void main(String[] args) {


MyClass cls = new MyClass();

cls.method();
cls.number =1;
cls.name = "홍길동";


MyClass cls1 = new MyClass();
cls1.number =2;
cls1.name ="성춘향";
cls1.method();

 

TV tv1=new TV();
tv1.isPowerOn=true;
tv1.channel=23;
tv1.volume=10;

tv1.maker="삼성";
tv1.method();

 

TV tv2= new TV();
tv2.isPowerOn =false;
tv2.channel =50;
tv2.volume=0;
tv2.maker="LG";
tv2.method();  

 

        }

     }

class TV{
boolean isPowerOn;
int channel;
int volume;
String maker;

void method() {
System.out.println("TV 회사는 "+maker+" TV는" +isPowerOn+"이고"+channel+"번을 보고있으며 볼륨 크기는"+volume+"입니다.");
}
}



class MyClass{
//멤버 변수
int number;
String name;

//멤버 메소드
void method() {
System.out.println("MyClass method()");
}
}

 

<출력문>
MyClass method()
MyClass method()
TV 회사는 삼성 TV는true이고23번을 보고있으며 볼륨 크기는10입니다.
TV 회사는 LG TV는false이고50번을 보고있으며 볼륨 크기는0입니다.
Comments