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