프로그래밍언어론-우정답(2021-04-04 / 182.3KB / 144회)
프로그래밍언어론 우 책형 1 쪽 프로그래밍언어론 문 1. 다음 C 프로그램의 실행 결과로 옳은 것은? #include void main() { int i, total = 0; for (i = 0; i < 10; i++) { if (!(i % 2)) continue; total = total + i; } printf("%d\n", total); } ① 20 ② 25 ③ 45 ④ 55 문 2. 에서 까지 순차적으로 실행하였을 때 출력되는 결과로 옳은 것은? #include int func() { static int x = 10; return x += 10; } void main() { int x; x = func(); x = func(); printf("a = %d\n", x); } #include int x = 10; void func() { x += 10; } void main() { int x = 10; func(); func(); printf("b = %d\n", x); } #include int x = 10; void func() { x += 10; } void main() { func(); func(); printf("c = %d\n", x); } ① a = 10 ② a = 10 b = 30 b = 30 c = 10 c = 30 ③ a = 30 ④ a = 30 b = 10 b = 30 c = 30 c = 30 문 3. 다음의 언어 L을 생성하는 문법으로 옳은 것은? (단, 언어 L의 알파벳은 {a, b, c}이다) L = { a ncbn | n ≥ 0 } ① S → aA A → aA | B B → Bb | c ② S → aAb A → c ③ S → aAb A → aAb | c ④ S → aSb | c 문 4. 다음 Java 프로그램의 실행 결과로 옳은 것은? class ClassA { private static ClassA instance = new ClassA(); private ClassA() { System.out.print("객체생성-"); } public static ClassA getInstance() { return instance; } } public class Test { public static void main(String[] args) { ClassA obj1 = ClassA.getInstance(); ClassA obj2 = ClassA.getInstance(); if (obj1 == obj2) System.out.println("같다"); else System.out.println("다르다"); } } ① 객체생성-객체생성-같다 ② 객체생성-같다 ③ 객체생성-객체생성-다르다 ④ 객체생성-다르다 문 5. 다음 C 프로그램의 실행 결과로 옳은 것은? #include void main() { int a, b, c, r; a = 4; b = 2; c = 3; r = a++ - ++b * (c 또는 문장이 들어가는 경우에 대한 설명으로 옳은 것은? human = (Human)mammal; human.mamma(); mammal = human; mammal.speak(); ① ㉠에 의 문장이 삽입될 경우, human은 Mammal 클래스의 객체를 참조하게 되므로 human.mamma(); 부분에서 문자열 “mamma”를 출력한다. ② ㉠에 의 문장이 삽입될 경우, human = (Human) mammal; 부분에서 컴파일 오류는 발생하지 않지만, 실행시 예외(exception)가 발생한다. ③ ㉠에 의 문장이 삽입될 경우, mammal은 Human 클래스의 객체를 참조하게 되므로 mammal.speak(); 부분에서 문자열 “speak”를 출력한다. ④ ㉠에 의 문장이 삽입될 경우, Human 클래스와 Mammal 클래스는 클래스형(class type)이 서로 다르기 때문에 mammal = human; 부분에서 컴파일 오류가 발생한다. 문 8. 다음 Java 프로그램의 실행 결과로 옳은 것은? import java.util.*; class Test { public static void main(String args[]) { LinkedList list = new LinkedList(); list.addLast(new Integer(20)); list.addLast(new Integer(10)); Iterator e = list.iterator(); while (e.hasNext()) { Integer num = (Integer)e.next(); System.out.print(num + " "); } while (!list.isEmpty()) { Integer num = list.removeLast(); System.out.print(num + " "); } } } ① 10 20 10 20 ② 10 20 20 10 ③ 20 10 10 20 ④ 20 10 20 10 문 9. 다음 C 프로그램의 실행 결과로 옳은 것은? #include int getnext(int a) { return (a * 2 + 1); } void main() { int i, j, k = 0; for (i = 1; i < 10; i++) for (j = 1; j < getnext(i); j++) k++; printf("k = %d\n", k); } ① k = 90 ② k = 99 ③ k = 110 ④ k = 120 문 10. 다음 C 프로그램의 실행 결과로 옳은 것은? #include void main() { int a[2][3] = {{-3, 14, 5}, {1, -10, 8}}; int *b[] = {a[0], a[1]}; int *p = b[1]; printf("%d, ", *b[1]); printf("%d, ", *(--p - 2)); printf("%d\n", *(*(a + 1) + 1)); } ① -3, -3, 8 ② -3, 3, -10 ③ 1, -3, -10 ④ 1, 3, 8 프로그래밍언어론 우 책형 3 쪽 문 11. 다음 C 프로그램은 2차원 배열 x의 각 원소 값을 두배로 만들기 위한 것이다. ㉠과 ㉡에 들어갈 내용으로 옳지 않은 것은? #include ㉠ // 배열의 원소 값을 두배로 하는 함수 정의 void main() { int x[2][3] = {{1, 2, 3}, {4, 5, 6}}; ㉡ // 함수 ㉠ 호출 } ① ㉠ void dubl(int ary[][], int row, int col) { int i, j; for (i = 0; i < row; i++) for (j = 0; j < col; j++) ary[i][j] *= 2; } ㉡ dubl(x, 2, 3); ② ㉠ void dubl(int ary[], int size) { int i; for (i = 0; i < size; i++) ary[i] *= 2; } ㉡ int i; for (i = 0; i < 2; i++) dubl(x[i], 3); ③ ㉠ void dubl(int ary[], int size) { int i; for (i = 0; i < size; i++) ary[i] *= 2; } ㉡ dubl(x[0], 6); ④ ㉠ void dubl(int *ary, int size) { int i; for (i = 0; i < size; i++) *(ary + i) *= 2; } ㉡ dubl(x[0], 6); 문 12. 다음 C 프로그램의 실행 결과로 옳은 것은? #include void swap(int i, int *j) { int tmp; tmp = i; i = *j; *j = tmp; } void main() { int i, j; i = 10; j = 9; swap(i, &j); printf("%d\n", i - 1); } ① 8 ② 9 ③ 10 ④ 11 문 13. 다음 C 프로그램의 실행 결과로 옳은 것은? #include int m(int x) { if (x == 1) return 3; else return 2 * m(x - 1); } void main() { printf("%d\n", m(5)); } ① 12 ② 24 ③ 48 ④ 72 문 14. 다음 Java 프로그램의 실행 결과로 옳은 것은? class C { int x = 10; void show_me() { System.out.println("상위클래스 C의 show_me() 메소드"); } void write() { this.show_me(); System.out.println("x 값은 : " + x); } } class D extends C { int x = 20; void show_me() { System.out.println("하위클래스 D의 show_me() 메소드"); } } class InheritThis { public static void main(String args[]) { D d = new D(); d.write(); } } ① 하위클래스 D의 show_me() 메소드 x 값은 : 10 ② 상위클래스 C의 show_me() 메소드 x 값은 : 10 ③ 하위클래스 D의 show_me() 메소드 x 값은 : 20 ④ 상위클래스 C의 show_me() 메소드 x 값은 : 20 문 15. Java의 접근지정자(access modifier)에 대한 설명으로 옳지 않은 것은? ① public으로 지정된 메소드는 모든 클래스에서 접근할 수 있다. ② private으로 지정된 메소드는 자신이 속한 클래스를 제외한 어떤 클래스에서도 접근할 수 없다. ③ protected로 지정된 메소드는 자신이 속한 클래스와 자신이 속한 클래스의 파생클래스에서만 접근할 수 있다. ④ 접근지정자가 없는 메소드는 자신이 속한 클래스 및 자신이 속한 클래스와 같은 패키지의 클래스에서도 접근할 수 있다. 프로그래밍언어론 우 책형 4 쪽 문 16. 다음 Java 프로그램이 정상적으로 실행되기 위해 ㉠과 ㉡에 들어갈 내용으로 옳은 것은? class ThreadTest implements ㉠ { public void run() { System.out.println("쓰레드 실행부분...."); } } public class ImplOfThread { public static void main(String[] args) { Thread t = new Thread(new ThreadTest()); System.out.println("Before"); ㉡ System.out.println("After"); } } ㉠ ㉡ ① Thread t.join(); ② Thread t.start(); ③ Runnable t.join(); ④ Runnable t.start(); 문 17. 다음 C 프로그램이 실행될 때 함수 fac()의 활성화 레코드(activation record)에 저장될 필요가 없는 요소는? #include int fac(int n) { if (n <= 1) return 1; else return (n * fac(n - 1)); } void main() { int x; x = fac(4); } ① 함수의 반환값(return value) ② 정적 링크(static link) ③ 복귀 주소(return address) ④ 매개 변수 n의 값 문 18. 다음 Java 프로그램을 컴파일하면 오류가 발생한다. 오류의 발생 원인으로 옳은 것은? abstract class Person { int age; protected String name; abstract String job(); public int getAge() { return age; } } public class HumanResource { public static void main(String[] args) { Person p = new Person(); } } ① 멤버변수 age에 접근지정자(access modifier)를 지정하지 않았다. ② 추상 클래스로부터 객체를 생성하였다. ③ 메소드 job()의 몸체가 정의되지 않았다. ④ 메소드 getAge()의 몸체가 추상클래스 내부에 포함되었다. 문 19. 다음 Java 프로그램에서 사용된 객체지향 언어의 특성이 아닌 것은? class Calc1 { protected int a, b; public Calc1() { a = 1; b = 2; } } class Plus extends Calc1 { void answer() { System.out.println(a + "+" + b + "=" + (a + b)); } void answer(int a, int b) { System.out.println(a + "+" + b + "=" + (a + b)); } } ① 오버라이딩(overriding) ② 상속(inheritance) ③ 캡슐화(encapsulation) ④ 오버로딩(overloading) 문 20. 다음 Java 프로그램의 실행 결과로 옳은 것은? class TestExcep { static int a, b; public static void div() { try { System.out.println("a를 b로 나눈 몫 = " + (a / b)); } catch(Exception e) { System.out.println("Exception 처리 루틴2 : "); } finally { System.out.println("div()의 finally 블록 수행"); } } public static void main(String args[]) { try { a = 1; b = 1; div(); } catch(Exception e) { System.out.println("Exception 처리 루틴1 : "); } finally { System.out.println("main()의 finally 블록 수행"); } } } ① a를 b로 나눈 몫 = 1 ② a를 b로 나눈 몫 = 1 div()의 finally 블록 수행 ③ a를 b로 나눈 몫 = 1 main()의 finally 블록 수행 ④ a를 b로 나눈 몫 = 1 div()의 finally 블록 수행 main()의 finally 블록 수행