ProgrammingModerateAmazon/Microsoft SDE MCQ · Java placement
What is printed?
What is printed?
char c = 'a';
c += 1;
System.out.print(('a' + 1) + "" + (char) ('a' + 1) + c);- A. bbb
- B. 98bb
- C. 98b98
- D. b98b
Correct answer: B. 98bb
'a' + 1 is int arithmetic, giving 98. Casting it back gives 'b', and the compound assignment c += 1 includes an implicit cast to char, so c is 'b' too.
More OOP with C++ and Java questions
- What is printed? java Object o = null; String s = (String) o; System.out.print(s + (o instanceof Object) + (s == null));
- What is printed? java List<String> l = new ArrayList<>(List.of("pear", "fig", "apple", "kiwi"))…
- Why does this class fail to compile? java class Util { static void f(List<String> l) { } static void f(List<Integer> l) { } }
- What is printed? java record Pt(int x, int y) { } // in main: Set<Pt> s = new HashSet<>(); s.add(new Pt(1, 2)); s.add(new Pt(1, 2))…
- Which line fails to compile? java class Animal { Animal make() { return new Animal(); } } class Dog extends Animal { Dog make() { return…
- What is printed? java PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder()); pq.addAll(List.of(3, 1, 4, 1, 5))…