Why do we use " " to define the can't we use ' ' and if no then please let me the reason behind that. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Why do we use " " to define the can't we use ' ' and if no then please let me the reason behind that.

Like why we write String var = "hello" And why String var = 'hello' not.

22nd Sep 2017, 10:06 AM
kanishka
kanishka - avatar
2 Respostas
+ 10
BecauseĀ charĀ andĀ StringĀ are two different data types, and how else is Java supposed to know whether you want a character or string of length 1? For example, given the methods : public void foo(String s) { } public void foo(char c) { } And the call : foo('a'); If Strings would be made using single quotes, how would Java know that its a char or a String?
22nd Sep 2017, 10:13 AM
Dev
Dev - avatar
0
Ok Thank you šŸ‘
23rd Sep 2017, 2:41 AM
kanishka
kanishka - avatar