• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Operator self test question and Flow Control doubt.

 
Ranch Hand
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ^_^
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic