ProgrammingModerateProduct-company placement · Java
What is printed?
What is printed?
char[] c = {'h', 'i'};
System.out.print(c);
System.out.print(" " + String.valueOf(c) + " " + c.length);- A. [C@… (a hash) hi 2
- B. hi [C@… (a hash) 2
- C. hi hi 2
- D. h i hi 2
Correct answer: C. hi hi 2
PrintStream has a print(char[]) overload that prints the characters, and String.valueOf(char[]) builds a String from them. Only concatenating the array itself ("" + c) would give the [C@… form.
More OOP with C++ and Java questions
- What is printed? java // static methods of the main class: static void up(String s) { s = s.concat("X"); } static void add(StringBuilder…
- What is printed? java Object a = new ArrayList<String>(); List<Integer> b = new LinkedList<>(); List<Integer> c = new ArrayList<>()…
- What happens when this interface is compiled? java interface Named { String name(); default boolean equals(Object o) { return o instanceof…
- Which of these is a valid functional interface (usable as a lambda target)?
- What is printed? java class T { String name = "outer"; void run() { Runnable a = () -> System.out.print(this.name + " "); Runnable b = new…
- What is printed? java // Java 16 or later record P(int x, int y) { } // in main: P a = new P(1, 2), b = new P(1, 2); System.out.print((a…