question about enthuware.ocpjp.i.v11.2.3201

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

Moderator: admin

Post Reply
dimitrilc
Posts: 35
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

question about enthuware.ocpjp.i.v11.2.3201

Post by dimitrilc »

Why is
A var declaration must have an initializer. Without the initializer, the compiler will not be able to deduce the type of the variable.
not a valid statement?

When I try to declare an empty var,

Code: Select all

public class CompileTimeConstant{
	public static void main(String[] args){
		var v1;
	}
}
compiler refuses to run and gives error,

Code: Select all

CompileTimeConstant.java:3: error: cannot infer type for local variable v1
                var v1;
                    ^
  (cannot use 'var' on variable without initializer)
1 error
error: compilation failed

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

Re: question about enthuware.ocpjp.i.v11.2.3201

Post by admin »

This is indeed a valid statement. But it is the explanation to the option number 4, which is an incorrect option. It explains why option 4 is incorrect.
If you like our products and services, please help us by posting your review here.

dimitrilc
Posts: 35
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

Re: question about enthuware.ocpjp.i.v11.2.3201

Post by dimitrilc »

admin wrote:
Sat Jun 06, 2020 8:02 pm
This is indeed a valid statement. But it is the explanation to the option number 4, which is an incorrect option. It explains why option 4 is incorrect.
Thank you. You are right. I thought the blue text in review mode was part of the answer. I totally face-palmed myself there. :o

dimitrilc
Posts: 35
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

Re: question about enthuware.ocpjp.i.v11.2.3201

Post by dimitrilc »

I am not sure if this is out of scope for the exam or not, but //1 can also be wrong. The TestClass.java file won't run if you run it with "java" and complains that it cannot find the main method.

To run this file, you must compile it first with javac, then run with java.

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

Re: question about enthuware.ocpjp.i.v11.2.3201

Post by admin »

The problem statement isn't asking about running the code.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests