This specification documents Java numerical advertising. Section 2 says that if any of the operands is of type double , then the result is of type double. This specification (which was added by @Januson) mentions that:
the type of conditional expression is the advanced type of the second AND third operand
Now, if we apply these two documents to our examples, we get the following:
System.out.println(System.getProperty("java.version"));
This is the version (release) of Java. This is a String .
System.out.println((true) ? (int)2.5 : 3.5);
In this case, the compiler looks at both parts of the conditional expression and decides the data type. (int) 2.5 is integer and 3.5 is a double . The result will be double . Thus, the integer part 2.5 (i.e. 2) will be passed to double .
System.out.println((true) ? (int)2.5 : 3);
In this case, the compiler looks at 2 integers, so the result is integer . The first case gives an integer , and the second case is also an integer , so the result will be in integer .
System.out.println((true) ? (int)2.5 + "" : 3.5);
In this case, the compiler looks at the first case and takes the integer part, which is 2. Now, since this number is added to the string, it becomes String . The result will also be a string. If you try to return 3.5, it will be returned as String , not double .