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.
2 ответов
+ 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?
0
Ok Thank you 👍