본문 바로가기

ETC/자격증

[정보처리기사실기]두목넷 무료 강의 Part 10 프로그래밍 언어 활용 11

반응형

https://youtu.be/qnrLJwWF4nQ

 

Q>

다음 Java 코드에서 에러가 발생하는 부분의 기호를 쓰시오.

 

A>

class Super {
    int x = 10;
    int y = 20;
    public void add() {
        System.out.printf("%d + %d = %d\n", x, y, x+y);
    }
}

class Sub extends Super{    // 상속
    int z = 30;
    public void add() {     // 오버라이드(재정의)
        System.out.printf("%d + %d = %d\n", x, y, x+y+z);
    }
}

public class Exam {     // 실행
    public static void main(String[] args) {
      1. Super a = new Super();        // 객체 생성
      2. Sub b = new Sub();
      3. Super c = new Sub();          // 자식 객체
      4. Sub d = new Super();          // 부모 객체
    }
}

 

4. Sub d = new Super();

/Exam.java:21: error: incompatible types: Super cannot be converted to Sub

반응형