This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
At line 9, you are actually comparing two unrelated classes. All enums are sub-classes of Enum class. And Enum and String class are not related to each other in any way whatsoever. So it will give you a compilation error. It is just like you are doing this new Integer(10) == "10" where the LHS is an instance of class Integer and RHS is of type String.
In the 11th statement you must read the documentation of Enum class. It states that it will only check if the object passed is same as the enum constant on which it is called. So it will return true if you call it like this
and not like this
Actually you know that they are meaningfully equal (i.e. RED and "RED") but for Java, they are two references of two different types (RED of type Enum and "RED" of type String)... If you have read about equals methods, then they are actually implemented like this
So Enum class also follows this pattern and returns false if the object passed is not of type Enum...