Загрузка...

💻 Java String Puzzle | 90% Get This Wrong! 😱 #shots #java

💻 Daily JAVA Challenge | Problem #28

#sh

Can you guess the output of this tricky Java question? 🤔
This one tests your understanding of the String Constant Pool and the difference between "==" and ".equals()".

👇 Code:

public class Test {
public static void main(String[] args) {
String s1 = "Java";
String s2 = "Ja" + "va";
System.out.println(s1 == s2);
}
}

🔘 Options:
A) true
B) false
C) Compilation Error
D) Runtime Error

✅ Correct Answer: A) true

💡 Explanation:
The expression ""Ja" + "va"" is resolved at compile time, so it becomes ""Java"". Both "s1" and "s2" point to the same object in the String Constant Pool. Hence, "==" returns true because it compares references.

🔥 Important Concept:

- "==" → compares memory reference
- ".equals()" → compares actual content

👍 If you found this helpful, like, share, and subscribe for more daily Java challenges!

#java #javaprogramming #coding #programming #javachallenge #code #developers #learnjava #codinglife #softwaredeveloper #tech #shorts #youtubeshorts #viral #trending
#shorts

Видео 💻 Java String Puzzle | 90% Get This Wrong! 😱 #shots #java канала CodeCraft Pro
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять