Telegram Group & Telegram Channel
Что выведет этот код на Java?


public class Main {
public static void main(String[] args) {
String a = "hello";
String b = "he" + "llo";
String c = "he";
String d = c + "llo";

System.out.println(a == b); // #1
System.out.println(a == d); // #2
System.out.println(a.equals(d)); // #3
}
}


🔢 Варианты ответа:

A)

true
true


B)

false
true


C)

false
true


D)

false
false


Правильный ответ: B

💡 Почему?
- Строки в Java — immutable и используют string pool.
-
a == btrue, потому что "he" + "llo" конкатенируется на этапе компиляции.
-
c + "llo" — создаёт новый объект во время выполнения.
-
a == dfalse, но a.equals(d)true, потому что .equals() сравнивает содержимое строк.

@javatg



tg-me.com/javatg/1802
Create:
Last Update:

Что выведет этот код на Java?


public class Main {
public static void main(String[] args) {
String a = "hello";
String b = "he" + "llo";
String c = "he";
String d = c + "llo";

System.out.println(a == b); // #1
System.out.println(a == d); // #2
System.out.println(a.equals(d)); // #3
}
}


🔢 Варианты ответа:

A)

true
true


B)

false
true


C)

false
true


D)

false
false


Правильный ответ: B

💡 Почему?
- Строки в Java — immutable и используют string pool.
-
a == btrue, потому что "he" + "llo" конкатенируется на этапе компиляции.
-
c + "llo" — создаёт новый объект во время выполнения.
-
a == dfalse, но a.equals(d)true, потому что .equals() сравнивает содержимое строк.

@javatg

BY Java


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/javatg/1802

View MORE
Open in Telegram


Java Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram is a cloud-based instant messaging service that has been making rounds as a popular option for those who wish to keep their messages secure. Telegram boasts a collection of different features, but it’s best known for its ability to secure messages and media by encrypting them during transit; this prevents third-parties from snooping on messages easily. Let’s take a look at what Telegram can do and why you might want to use it.

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

Java from ca


Telegram Java
FROM USA