• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum & switch

 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




In the above code "this" means a object?
How can you explain how to get the output as "c"?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this means the object which is currently executing the code, in your case, in which object, you've called the getGrade() method? If this is clear, then you can find the solution for your second question.
 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the example can you take "GOOD" as a object?explain
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejaka samarakoon wrote:in the example can you take "GOOD" as a object?explain

Yea. every enums are object. They will behave like any other java objects, but in creation and class definition, there are differs. So in your case, you invoke the method getGrade() on GOOD object, and in that method, this means GOOD object. Is it clear?
 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I got the idea javascript:emoticon('');
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejaka samarakoon wrote:Thanks I got the idea javascript:emoticon('');

You are Welcome, BTW, javascript isn't work!
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also I want to add that even if the enums have Constructors we cannot create the objects using the new keyword like we do for classes
we cannot call the enum constructor explicitly
also enum constants have the constant specific bodies which are much similar to the anonymous inner classes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic