LearnFrenzy
Sign in Take a free test

Static and Final Keywords · Predict the Output · Question 12

Strings are immutable Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following Java program?

Main.java
public class Main {
    public static void main(String[] args) {
        String s = "java";
        s.toUpperCase();
        s.concat(" rocks");
        String t = s.replace('j', 'l');
        System.out.println(s + " " + t);
    }
}
  • A java lava Correct
  • B JAVA ROCKS lava
  • C java rocks lava rocks
  • D lava lava
Correct Answer: Option A

String methods return new strings; ignoring the result leaves s unchanged.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links