달력

62025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30


/*
인터페이스 interface
interface 키워드를 사용한다.
상수와 추상 메소드로만으로 구성된다.
final, abstract 키워드를 따로 붙이지 않는다.
interface는 객체를 생성할 수 없다.
상속 시 implements(구현) 키워드를 사용한다.
상속 시 추상 메소드는 빠짐없이 구현해야 한다.
인터페이스는 음식점의 메뉴판과 같다.
다중 상속이 가능하다.
*/

interface Inter1
{
 int a = 10;          // final    초기화 해야 한다.
 
 public int getA();       // abstract 구현할 수 없다.
}

class InterEx1 implements Inter1
{
 public int getA()
 {
  return a;
 }

 public static void main( String[] args )
 {
  // Inter1 in = new Inter1();     // 객체 생성을 할 수 없다.
  InterEx1 ie = new InterEx1();
  System.out.println( "a : " + ie.getA() );  
 }
}

Posted by cdprkr2077
|