다음 코드의 출력 결과는 무엇인가?
public class Test { public static void main(String[] args) { String s = "APCSA"; System.out.println(s.substring(1, 4)); } }
A. APC
B. PCS
C. PCS A
D. PCS
E. PC S아래 코드에서 컴파일 오류가 발생하는 이유로 옳은 것은?
public class Person { private String name; public Person(String name) { this.name = name; } public void setName() { name = newName; } }
A. 생성자의 파라미터 타입이 잘못되었다.
B. setName 메서드에 파라미터가 없어서 newName을 참조할 수 없다.
C. name 필드는 private이어서 setName에서 접근할 수 없다.
D. 클래스 이름과 파일 이름이 다르다.
E. setName 메서드에 반환 타입이 잘못 지정되었다.다음 코드 실행 후 변수
count
의 값은?public class Counter { public static int count = 0; public Counter() { count++; } public static void main(String[] args) { Counter c1 = new Counter(); Counter c2 = new Counter(); new Counter(); System.out.println(Counter.count); } }
A. 1
B. 2
C. 3
D. 0
E. 컴파일 오류ArrayList 관련 문제:
import java.util.*; public class ListTest { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); list.add(5); list.add(10); list.add(15); list.remove(1); System.out.println(list.get(1)); } }
실행 결과는 무엇인가?
A. 5
B. 10
C. 15
D. IndexOutOfBoundsException
E. 컴파일 오류재귀 메서드의 반환 값은?
public class Recursion { public static int factorial(int n) { if (n <= 1) return 1; return n * factorial(n - 1); } public static void main(String[] args) { System.out.println(factorial(4)); } }
A. 6
B. 24
C. 12
D. 16
E. StackOverflowError상속 및 오버라이딩 관련:
class Animal { public String speak() { return "???"; } } class Dog extends Animal { public String speak(int volume) { return "Bark"; } } public class Main { public static void main(String[] args) { Animal a = new Dog(); System.out.println(a.speak()); } }
실행 시 결과는?
A. Bark
B. ???
C. 컴파일 오류
D. NullPointerException
E. 실행되지 않음StringBuilder 사용:
public class SBTest { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Hello"); sb.append(" World"); sb.delete(5, 6); System.out.println(sb.toString()); } }
출력 결과는?
A. HelloWorld
B. Hello World
C. Hell World
D. HelloWorld
E. Hello orld2차원 배열 문제:
public class Array2D { public static void main(String[] args) { int[][] a = { {1,2}, {3,4,5}, {6} }; int sum = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { sum += a[i][j]; } } System.out.println(sum); } }
sum의 최종 값은?
A. 15
B. 21
C. 16
D. 컴파일 오류
E. 10static 메서드와 인스턴스 메서드 차이:
public class MathUtil { public static int add(int x, int y) { return x + y; } public int multiply(int x, int y) { return x * y; } } public class Main2 { public static void main(String[] args) { MathUtil util = null; System.out.println(util.add(2, 3)); } }
위 코드를 실행하면?
A. 5
B. NullPointerException
C. 컴파일 오류
D. 0
E. 실행되지 않음향상된 for문 활용:
public class ForEachTest { public static void main(String[] args) { String[] arr = {"A","B","C"}; for (String s : arr) { s = s + "X"; } System.out.println(arr[0] + arr[1] + arr[2]); } }
출력 결과는?
A. AXBXCX
B. ABC
C. ABCX
D. A B C
E. 컴파일 오류
정답 키(참고용)
- B
- B
- C
- C
- B
- B
- A
- B
- A
- B
'취준생대상' 카테고리의 다른 글
자바 코딩 테스트 문제 4 (0) | 2025.05.07 |
---|---|
자바 코딩 테스트 문제 3 (0) | 2025.05.07 |
자바 코딩 테스트 문제 1 (0) | 2025.05.07 |
AWS 트래픽 처리 - 면접질문 (0) | 2025.03.28 |
머신러닝에서 실제 데이터에서 성능이 안좋다면? - 면접질문 (0) | 2025.03.25 |