| Author |
enum & switch
|
thejaka samarakoon
Ranch Hand
Joined: Jul 20, 2010
Posts: 56
|
|
In the above code "this" means a object?
How can you explain how to get the output as "c"?
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
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.
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
thejaka samarakoon
Ranch Hand
Joined: Jul 20, 2010
Posts: 56
|
|
|
in the example can you take "GOOD" as a object?explain
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
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
Joined: Jul 20, 2010
Posts: 56
|
|
Thanks I got the idea javascript:emoticon(' ');
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
thejaka samarakoon wrote:Thanks I got the idea javascript:emoticon('  ');
You are Welcome, BTW, javascript isn't work!
|
 |
Prasad Kharkar
Ranch Hand
Joined: Mar 07, 2010
Posts: 438
|
|
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
|
SCJP 6 [86%] June 30th, 2010
If you find any post useful, click the "plus one" sign on the right
|
 |
 |
|
|
subject: enum & switch
|
|
|