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: |

How Does Telegram Make Money?

Telegram is a free app and runs on donations. According to a blog on the telegram: We believe in fast and secure messaging that is also 100% free. Pavel Durov, who shares our vision, supplied Telegram with a generous donation, so we have quite enough money for the time being. If Telegram runs out, we will introduce non-essential paid options to support the infrastructure and finance developer salaries. But making profits will never be an end-goal for Telegram.

Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.

Java from no


Telegram Java
FROM USA