Why can't i do this? I understand that concatenation of a int and a string or with boolean,(true or false) is possible, but not an addition of boolean with an int.
What exactly happens when u add a int with a boolean? Why does it show an error?
System.out.println(a.length() + a.startsWith("a"));
i also understand that the work around for this code is
System.out.println(""+a.length() + a.startsWith("a"));
which uses concatenation.
Because the + operation has different functions.
In the first example you try Number + Boolean. And this doesn't make sense, so the compiler gives an error.
In the second example you try String + Number (which is allow as String - concentation and returns a String). Afterwards you try String + boolean (which is also allowed)