About Question enthuware.ocpjp.v7.2.1406 :

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

Moderator: admin

Post Reply
muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

About Question enthuware.ocpjp.v7.2.1406 :

Post by muttley »

Isn't it better <boolean_expression> : <any_expression_but_Notvoid>? Because the expression can't return void. With <any_expression_but_void> seems that the return may be void.

Tks

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

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by admin »

I guess it could be interpreted that way. You could have a method that returns void and that would be invalid as well. So, in a way, you can have an expression that results in void.

-Paul.
If you like our products and services, please help us by posting your review here.

muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by muttley »

Sorry, but now I am a little confuse.
For this statement:

Code: Select all

public void assertTest(List v) {
    assert v.size() == 10 : v.clear();
}
The explain say:
"Invalid because List.clear() returns void and  boolean : void does not satisfy <boolean_expression> : <any_expression_but_void>, which is required for an assert statement."

I understood that this question is wrong because return void and you just answer that can do it.
Could you explain a feel better.
I know, I'm making mess alone, but I don't know where.

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

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by admin »

No, I said, "You could have a method that returns void and that would be invalid as well."

My statement, "So, in a way, you can have an expression that results in void." was in response to your statement, "Because the expression can't return void. "

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Sai Divya sree
Posts: 14
Joined: Mon Jun 20, 2016 11:16 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by Sai Divya sree »

can second expression of assert statement be an object reference?I mean just the reference not the actual object.
Like in this case:
/code
public void assertTest(List v){
assert v.size()==10: v ;
}
/code
I am preparing from study guide by K&B.It says,
illegal assert statement :
assert(x==1):vallidAssert va;
Because the statement doesn't return a value.
So I am little confused if references are valid as second exp in assert statement?

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

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by admin »

What happened when you tried it out?
BTW, in Java you always refer to an object using a reference. So I am not sure what you mean by just the reference not the actual object.
-Paul.
If you like our products and services, please help us by posting your review here.

Sai Divya sree
Posts: 14
Joined: Mon Jun 20, 2016 11:16 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by Sai Divya sree »

with just a reference :(Illegal assert statement)
assert(x==1):vallidAssert va; // do not return a value.
with object:(Legal assert statement )
assert(x==1):new validAssert();
As per the book... The second expression,used only with simple version of an assert statement ,can be anything that results in a value.

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

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by admin »

assert(x==1):vallidAssert va;
This is illegal syntax. Not sure why are you expecting it work. You should go through this to understand the syntax clearly: http://docs.oracle.com/javase/7/docs/te ... ssert.html

Or check with the book authors what do they mean about it.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

bvrulez
Posts: 33
Joined: Sat Feb 15, 2020 12:44 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by bvrulez »

What is the return value of "v = new ArrayList<>();" ?

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

Re: About Question enthuware.ocpjp.v7.2.1406 :

Post by admin »

v = new ArrayList<>(); is an expression. Every expression itself has a value (which, in this case, is same as the value being assigned to v).
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 54 guests