aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operator self test question and Flow Control doubt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operator self test question and Flow Control doubt." Watch "Operator self test question and Flow Control doubt." New topic
Author

Operator self test question and Flow Control doubt.

David Samer
Ranch Hand

Joined: Feb 08, 2012
Posts: 49

Greetings there people

Here I come again with 2 doubts this time, one from a self test and another from an explanation in a chapter I don't understand >_< !

Let's go by parts:

==> Self test questions (Regarding operators this time but it has nothing to do with operators , more like enums )



I don't know there how exactly for works. I believe while its checking the enum (it returns an array as said), then I believe declared Days type variable "d" , takes F value once it finds it on the enum, assigning it to d2 variable.

When comes to ternary operator , ¿ isn't it comparing something like : Days.TH = Days.F ? Of course, due answer I am wrong, but I don't know why. (Probably in mistaken with reasoning)


====

Second part, the doubt about an explanation regarding flow control.

Reading about switch statement and case .

Here what it says:



Wow! how is so? Aren't both vars final int? . So then? (Or its due b takes value 2 in another line instead when declared? )

=======

That's all.

Thanks in advance for the answers ^_^
Mahesh Murugaiyan
Greenhorn

Joined: Jun 25, 2009
Posts: 21
Hi David,

For the Enum question, on line 8, there is a "if(d.equals(Days.F)) break".
Because of this break, it will not go to line 9, where d2 will become Days.F.
So d2 retains its older value Days.TH. For this reason, the ternary operator's will return true, that is, d1(Days.TH) == d2(Days.TH). Hence the result "same old".
Hope this makes sense!

Cheers
Mahesh
Mahesh Murugaiyan
Greenhorn

Joined: Jun 25, 2009
Posts: 21
Hi David,

While exlploring your second question on final, i was little puzzled. My understanding goes like this:
1. final variables can be assigned value only once. So, the lines 8,9 looks good to me.
2. However, "case" doesnt seem to accept a final variable which was not initialized during declaration. This seems odd to me!





Cheers
Mahesh
David Samer
Ranch Hand

Joined: Feb 08, 2012
Posts: 49

Mahesh Mak wrote:Hi David,

For the Enum question, on line 8, there is a "if(d.equals(Days.F)) break".
Because of this break, it will not go to line 9, where d2 will become Days.F.
So d2 retains its older value Days.TH. For this reason, the ternary operator's will return true, that is, d1(Days.TH) == d2(Days.TH). Hence the result "same old".
Hope this makes sense!

Cheers
Mahesh


Oh my... Can you believe I haven't seen that break there until you said it? oh hell... (and used = instead == ) *face palm* .

Thanks Mahesh

Regarding second question, I'm also confused too thinking the same, I do see line 8 and line 9 perfectly good there!

Let's hope someone can help us clarifying it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operator self test question and Flow Control doubt.