interface Cha { void skill(); } class A { void Attack(Cha b) { b.skill(); System.out.println("공격"); } } class B implements Cha { public void skill() { System.out.println("마법사"); } } class C implements Cha { public void skill() { System.out.println("전사"); } } class D implements Cha { public void skill() { System.out.println("전사"); } } // //class C{ //void skill() { //System.out.println("전사"); //}..
Java
문제 아래의 2개 클래스와 1개의 인터페이스를 작성하고, 실행결과를 출력하시오! Stack (인터페이스) StringStack, StringStackExample Stack(인터페이스) 멤버함수 int length(void) *추상메서드 Object pop(void) *추상메서드 void push(Object s) *추상메서드 StringStack Class(조상클래스) 멤버변수 private String[] s private int n 멤버함수 public int length(void) *알아서 구현 public Object pop(void) *알아서 구현 public void push(Object s) *알아서 구현 StringStackExample(실행클래스) 결과 스택크기 입력: 5 5개의 스택영..
문제 아래의 3개의 클래스와 2개의 인터페이스를 작성하고, 실행결과를 출력하시오! MobilePhone, MP3 (인터페이스) PDA, SmartPhone, SmartPhoneExample MobilePhone(인터페이스) 멤버함수 void sendCall(void) void receiveCall(void) void sendSMS(void) void receiveSMS(void) MP3(인터페이스) 멤버함수 void play(void) void stop(void) PDA Class(조상클래스) 멤버함수 int calcuate(int a, int b) *출력결과보고 구현 SmartPhone Class(자식클래스)->인터페이스 구현(2개) 멤버함수 void sendCall(void) 출력결과 보고 재 정의 ..
문제 아래의 3개의 클래스와 1개의 인터페이스를 작성하고, 실행결과를 출력하시오! RemoteControl(인터페이스) Television, Audio, RemoteControlExample RemoteControl(인터페이스) 멤버변수 int MAX_VOLUME *10으로 초기화 int MIN_VOLUME *0으로 초기화 멤버함수 void turnOn(void) *추상메서드 void turnOff(void) *추상메서드 void setVolume(int volume) *추상메서드 default void setMute(boolean mute) *디폴트메서드 출력결과 보고 구현 static void changeBattery(void) *정적메서드 출력결과 보고 구현 Television Class(구현클래스..
문제 아래의 4개 클래스와 1개의 인터페이스를 작성하고, 실행결과를 출력하시오! Vehicle (인터페이스) Bus, Taxi, Driver, DriverExample Vehicle(인터페이스) 멤버함수 void run(void) *추상메서드 void stop(void) *추상메서드 Bus Class(구현클래스) 멤버함수 void run(void) void stop(void) Taxi Class(구현클래스) 멤버함수 void run(void) void stop(void) Driver(독립클래스) 멤버함수 void drive(Vehicle) void stop(Vehicle) DriverExample(실행클래스) 결과 버스가 달립니다. 버스가 멈춥니다. 택시가 달립니다. 택시가 멈춥니다. 코드 interfa..
문제 아래의 5개의 클래스를 작성하고, 메인에서 아래와 같은 실행 결과를 출력하시오(추상 클래스) Ship, Boat, Cruise, ShipUtill, ShipExample Ship Class(조상 / 추상클래스) 멤버변수 int person int weapon 멤버함수 생성자구현 public abstract int move(void) *인원 public abstract int carry(void) *무기 Boat Class(자손클래스) 멤버변수 String name 멤버함수 public int move(void) *인원 public int carry(void) *무기 public String name(void) Cruise Class(자손 클래스) 멤버변수 String name 멤버함수 public ..
[문제] 15번 문제를 활용하여 아래의 출력 형태로 만들어보자 (연결 리스트를 이용한 스택 구조를 만들어보자!) pStart = pStart.Next;만 해줬다 pStart.Next = null; 과 같은 처리를 해주지 않은 이유는 자바는 GC(Garbage Collection에 의해) 사용되지 않는 객체가 생기면 자동으로 메모리를 회수해가기 때문이다. [코드] class Shape { // Shape Next; void paint() { draw(); } void draw() { System.out.print("Shape을 만듭니다."); } } class Circle extends Shape { void draw() { System.out.print("Circle"); } } class Rectang..
[문제] 아래의 6개의 클래스를 작성하고, 메인에서 아래와 같은 실행결과를 출력하시오(다형성) Shape,Circle,Rectangle,Triangle,Node,ShapeExample (각각 "Shape", "Circle", "Rectangle", "Traingle" 이라 출력하는 기능을 가지고 있다. 이 클래스들을 이용하여 아래 그림1과 같이 연결 리스트로 구성한 후, 아래와 같이 출력하는 프로그램을 작성하라. * 단, 다형성을 구현하는 프로그램으로 작성하라. ) Shape Class(조상클래스) 멤버함수 void paint() void draw() *main에서 pStart와 pLast를 사용하자! 실행화면 1.Circle 2.Triangle 3.Rectangle 4.Print 5.Exit : 1 C..