Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

JAVA PROGRAMMING. PLZ HELP! Which of the following is false about the expression a +b? A) If a is a string and b is a string, the result is a string. B) If a is an int and b is an int, the result is an int. C) If a is a string and b is an int the result is a string. D) If a is a int and b is a string, the result is an int.

OpenStudy (anonymous):

Will award Medal

OpenStudy (bibby):

You can just try them all out. The main difference arises in C/D ``` System.out.println("c " + 4); int a = 3+"d"; ```

OpenStudy (anonymous):

I don't understand how to try them out, this is my first year of Java Programming, and I don't know a dang about anything. I'm online schooled, so my teacher never tells me anything...

OpenStudy (bibby):

OK. Well it's not entirely necessary to write out a whole program just to test this out. Logically, you should be able to see, that just like in algebra, you can only compare apples and apples unless you can typecast. For example. 3 + 4.5 == 7.5 but you wouldn't be able to add a string and an int and store it in an int. Ints are whole numbers. On the other hand characters can be interpreted as ints so you can do something like int a = 'a'+24; This is a pretty poor explanation, hmm.

OpenStudy (anonymous):

So the answer is D?

OpenStudy (bibby):

yeah.

OpenStudy (anonymous):

Thanks So much!

OpenStudy (anonymous):

probably you can't do a + b (a -> int , b->string) because you need a cast on b like Integer.parseIntegeR(b) , am i right ?

OpenStudy (bibby):

correct, but no wrapper classes are being used here. just primitives

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!