NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed. (sponsored)
In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.
Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.
Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
We (i.e. Diego and me) have a problem with an enum question.
The question is (+ : ok, - : wrong):
An enum is a special kind of class. Which of the following are correct statements?
+ 1. It is implicitly static
- 2. It is implicitly final
+ 3. It is implicitly final unless it contains constant-specific class bodies.
+ 4. It cannot be declared abstract
+ 5. It is implicitly abstractif each abstract method is overridden in the constant-specific class body of every enum constant.
And we have different opinion about option 1. and 5.
Can someone provide us with a definitive answer about this (and with a link to some "official" website).
Choice 1 is not true.
Nested
enums are implicitly static. Top level classes cannot be static. This is explicitly mentioned in the spec (JLS, 3rd edition, chapter 8.9, page 250)
Choices 2 to 4 are ok
Choice 5 is true, enums with abstract methods are implicitly abstract. Every class with an abstract method is abstract and the generated class must be abstract (let alone to preserve compatibility). In this case it is not final (choices 2 vs. 3!). Unfortunately it is not explicitly mentioned in the spec and I could not find a website (only done a quick search). You can verify it by analyzing the class file of such an enum.
I would suggest that Diego provides a reference that proves choice 5 or deletes this choice because it's really difficult to argument. The wording of choice 5 is a bit awkward anyway IMHO. If an enum has abstract methods, they
must
be overridden in the constant-specific class body. The choice text sounds like the enum is implicitly abstract only if they are overridden.
Hi all,
I believe that (or I understand that ;)):
Enums are implicitly static because no outer object is associated with an enum constant.
And, abstract is illegal modifier for Enums, but if you declared an abstract method in enum, it is abstract.
Diego, I would suggest that you change the question and add an explanation. I would not use the website you posted as a source since it contains questionable and debatable statements. Thomas is the leader of this exam, so it's his decision at last.
Alwin,
I never say that an enum can be declared as abstract and the question say:
It is implicitly abstract if each abstract method is overridden in the constant-specific class body of every enum constant.
I say that if an enum has an abstract method then the enum is "implicitly" abstract, but it is not declared (necessarily) abstract.
For instance:
public enum Test {
A() {
public void xx() {
...
}
};
public abstract void xx();
}
Test is abstract even though it is not declared abstract
Diego, I know that you didn't claim an enum could be declared abstract. It cannot, that's choice 4 of your original question. And you are right with choice 5 and your explanation. I just argue that we shouldn't use this website as a reference since it contains wrong statements (or, at least, mistakable wording). I for myself would delete choice 5 without an unambiguous and unmistakable reference since this point is correct but not really clear to everyone and may lead to discussions/arguments.
Enum question #2572
At 7:35 PM on Apr 30, 2007, Thomas Schroeder wrote:
Fresh Jobs for Developers Post a job opportunity
We (i.e. Diego and me) have a problem with an enum question.
The question is (+ : ok, - : wrong):
And we have different opinion about option 1. and 5.
Can someone provide us with a definitive answer about this (and with a link to some "official" website).
Thanks,
Thomas
8 replies so far (
Post your own)
Re: Enum question #2572
Hi Thomas, DiegoChoice 1 is not true. Nested enums are implicitly static. Top level classes cannot be static. This is explicitly mentioned in the spec (JLS, 3rd edition, chapter 8.9, page 250)
Choices 2 to 4 are ok
Choice 5 is true, enums with abstract methods are implicitly abstract. Every class with an abstract method is abstract and the generated class must be abstract (let alone to preserve compatibility). In this case it is not final (choices 2 vs. 3!). Unfortunately it is not explicitly mentioned in the spec and I could not find a website (only done a quick search). You can verify it by analyzing the class file of such an enum.
I would suggest that Diego provides a reference that proves choice 5 or deletes this choice because it's really difficult to argument. The wording of choice 5 is a bit awkward anyway IMHO. If an enum has abstract methods, they must be overridden in the constant-specific class body. The choice text sounds like the enum is implicitly abstract only if they are overridden.
Kind regards,
Alwin
Re: Enum question #2572
Hi all,I believe that (or I understand that ;)):
Enums are implicitly static because no outer object is associated with an enum constant.
And, abstract is illegal modifier for Enums, but if you declared an abstract method in enum, it is abstract.
Source:
http://www.roseindia.net/javacertification/scjp5/DeclarationsInitializationandScoping.shtml#c1s1
Regards,
diego
Re: Enum question #2572
Ok, Alwin.The outer Enum cannot be static, but the inner Enums are implicitly static.
- 1. It is implicitly static (false)
- 2. Nested enums are implicitly static (true)
it may look nice?
Re: Enum question #2572
Quote from the website you posted:> It [an enum] cannot be declared abstract unless each abstract method is overridden in the constant-specific class body of every enum constant.
This is definitely wrong because an enum can never be declared abstract.
Quote from JLS 3rd edition page 250
> Enum types must not be declared abstract; doing so will result in a compile-time error.
Re: Enum question #2572
Diego, I would suggest that you change the question and add an explanation. I would not use the website you posted as a source since it contains questionable and debatable statements. Thomas is the leader of this exam, so it's his decision at last.Re: Enum question #2572
Alwin,I never say that an enum can be declared as abstract and the question say:
It is implicitly abstract if each abstract method is overridden in the constant-specific class body of every enum constant.
I say that if an enum has an abstract method then the enum is "implicitly" abstract, but it is not declared (necessarily) abstract.
For instance:
public enum Test {
A() {
public void xx() {
...
}
};
public abstract void xx();
}
Test is abstract even though it is not declared abstract
Re: Enum question #2572
Thomas, please change the question if you believe that it is wrong and then I accepted the modifications.Thanks.
Diego
Re: Enum question #2572
Diego, I know that you didn't claim an enum could be declared abstract. It cannot, that's choice 4 of your original question. And you are right with choice 5 and your explanation. I just argue that we shouldn't use this website as a reference since it contains wrong statements (or, at least, mistakable wording). I for myself would delete choice 5 without an unambiguous and unmistakable reference since this point is correct but not really clear to everyone and may lead to discussions/arguments.