About Question enthuware.ocajp.i.v7.2.1194 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1194 :

Post by ETS User »

In solution description , you mentoned
C:\works\nbtestproject\src\TestClass.java:46: reference to println is ambiguous, both method println(char[]) in java.io.PrintStream and method println(java.lang.String) in java.io.PrintStream match System.out.println(null + true); //1

Shouldn't there be System.out.println(null); to back up this statement, because System.out.println(null/true + true/null);always give compilation msg : "Operator + cannot be applied to null/boolean or boolean/null"

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1194 :

Post by admin »

No, compiler thinks that System.out.println(null + true); matches System.out.println(String); as well as System.out.println(char[]); because it is not able to figure out the type of null+true. So both the methods are kind of equidistant from this call.

HTH,
Paul.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1194 :

Post by flex567 »

>String getString() { return null; }
How would this even compile if null is not a String?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1194 :

Post by admin »

Java allows returning null from any method whose return type is a reference type.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests