Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Does concatenation take precedence over addition? What gets printed out with the following code?

0
Posted

Does concatenation take precedence over addition? What gets printed out with the following code?

0

public class concat_test { public static void main (String[] argv) { int i=5, j=6; System.out.println (i+j); } } Solution: addition has precedence and thus 11 gets printed out. However, parsing is done left to right, and can create strange effects: public class concat_test { public static void main (String[] argv) { int i=5, j=6; System.out.println (i+j); // 11 System.out.println ((i)+(j)); // 11 System.out.println (i + “” + j); // 56 System.out.println (“” + i + j); // 56 System.out.println (i + j + “”); // 11 } } • When the compiler compiles a class that imports a package, is the package compiled too? The answer is simple, but complicated to test: the compiler does it best to use a current version. Here’s a bunch of tests and a conclusion: • I created a simple class and placed it within a package. • I created another test class that used the package. • Test 1: • I did not compile the package class at all and tried compiling the test class. • The compiler compiled the package class fo

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123