์ถ์ ๋ฉ์๋์ ์์๋ง์ผ๋ก ๊ตฌ์ฑ
๋ชจ๋ ๋ฉ์๋๋ abstract public์ด๋ฉฐ ์๋ต ๊ฐ๋ฅ
์์๋ public static final ํ์ ์ด๋ฉฐ ์๋ต ๊ฐ๋ฅ
์ธํฐํ์ด์ค์ ๊ฐ์ฒด ์์ฑ ๋ถ๊ฐ
๋ค๋ฅธ ์ธํฐํ์ด์ค ์์ ๊ฐ๋ฅ
์ธํฐํ์ด์ค์ ๋ค์ค ์์ ๊ฐ๋ฅ
์ธํฐํ์ด์ค ํ์ ์ ๋ ํผ๋ฐ์ค ๋ณ์ ์ ์ธ ๊ฐ๋ฅ
implements
public interface Phone { //interface๋ก ์์ฑ
void sendCall();
void receiveCall();
}
interface MobilePhone extends Phone{
void sendSMS();
void receiveSMS();
}
interface MP3{
void play();
void stop();
}
class PDA{
int calc(int a, int b) {
return a+b;
}
}
public class InterfaceEx extends PDA implements MobilePhone, MP3{ //๋ฉ์ธ
@Override
public void sendCall() {
System.out.println("์ ํ ๊ฑธ๊ธฐ");
}
@Override
public void receiveCall() {
System.out.println("์ ํ ๋ฐ๊ธฐ");
}
@Override
public void play() {
System.out.println("์์
์ฌ์");
}
@Override
public void stop() {
System.out.println("์์
์ค์ง");
}
@Override
public void sendSMS() {
System.out.println("๋ฉ์์ง ๋ณด๋ด๊ธฐ");
}
@Override
public void receiveSMS() {
System.out.println("๋ฉ์์ง ๋ฐ๊ธฐ");
}
public static void main(String[] args) {
InterfaceEx obj = new InterfaceEx();
obj.sendCall(); obj.receiveCall();
obj.sendSMS(); obj.receiveSMS();
obj.play(); obj.stop();
System.out.println("obj.calc(2,3) => "+obj.calc(2, 3));
}
}
728x90
๋ฐ์ํ
0