I would like to ask for the error "Random can not be resolved to a type" on the page 16, Chapter 1.
It says the code below generates an error as Random can not be resolved to a type but when I test it it gives an error like "error: cannot find symbol".
Code is :
Could you please inform me if you get the same error that I get while compiling with Java SE 11.2
javac ImportExample.java
ImportExample.java:3: error: cannot find symbol
Random r = new Random(); // DOES NOT COMPILE
^
symbol: class Random
location: class ImportExample
ImportExample.java:3: error: cannot find symbol
Random r = new Random(); // DOES NOT COMPILE
^
symbol: class Random
location: class ImportExample
2 errors
Mehmet Tahir Dede wrote:It says the code below generates an error as Random can not be resolved to a type but when I test it it gives an error like "error: cannot find symbol".
To me not quite clear what are you trying to address here, whether the wording in error message is different comparing spoken language explanation what will happen vs actual compilation error given by the compiler. Or you expected something totally different in general?
I am aware that when we add the library code will not give any error. Problem here is the error that I get is different than the error mentioned in the book OCP Java Developer 11, page 16, chapter 1.
Dear Pawel,
Thank you so much for your reply too.
I see that you are getting the same error as I get. This means problem is about the book' s error message. Most probably book writes the error which belongs to an older JDK than JDK11.
"DOES NOT COMPILE" is never the error you should expect to see. It's what we put in comments when code does not compile. You aren't expected to know the exact text of compiler errors for the exam. Just whether it does or not.