About Question enthuware.ocpjp.v7.2.1406 :
Moderator: admin
-
- Posts: 19
- Joined: Thu Feb 28, 2013 9:47 am
- Contact:
About Question enthuware.ocpjp.v7.2.1406 :
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
Tks
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 19
- Joined: Thu Feb 28, 2013 9:47 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
Sorry, but now I am a little confuse.
For this statement:
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.
For this statement:
Code: Select all
public void assertTest(List v) {
assert v.size() == 10 : v.clear();
}
"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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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.
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.
-
- Posts: 14
- Joined: Mon Jun 20, 2016 11:16 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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?
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?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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.
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.
-
- Posts: 14
- Joined: Mon Jun 20, 2016 11:16 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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.
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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.
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.
-
- Posts: 33
- Joined: Sat Feb 15, 2020 12:44 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
What is the return value of "v = new ArrayList<>();" ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1406 :
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.
Who is online
Users browsing this forum: No registered users and 246 guests