Re: Interesting Java interview question
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Thu, 20 Mar 2008 13:38:43 GMT
Doug Dunn wrote:
I hate the way this news group has gone to hay. It used to be a good, active news group. C# advocates are punk for bothering other programmers in this group. I have prepared www.javaspec.org/wiki/Is_Java_dying%3F in response to their continual nonsense. Please get a life and leave this newsgroup alone.
Have you looked at the numerous subgroups of c.l.java, e.g., c.l.j.programmer? I get ~ 80 - 100 messages/day on that newsgroup, far from dead.
Meanwhile, this appears to me to just be to sets of arbitrary blocks-- the innnermost {{}}-- inside of an anonymous class body. The only question here is this:
Not quite.
new Object() { // Anonymous class declaration
{ // Anonymous class constructor declaration
{ // Arbitrary scope creation
}
}
}
You've declared a constructor as well (albeit one identical to the default constructor).
Anonymous classes implicitly subclass the class in which they are declared.
Where's the question mark, if it's a question?
This is also an incorrect or at best misleading statement. The anonymous class that is declared is a subclass of Object, nothing more, nothing less. Certainly, the output of this snippet does change depending on the class in which it was declared, but the anonymous class does not extend it.
The question is seeking to find out if the reader knows this because in isolation it is not possible to know what will print.
The question, I think, is trying to identify the following aspects of Java knowledge:
1. Anonymous classes, esp.
1a. Constructors of said classes
1b. Name of said class
2. Arbitrary scope creation
3. What Object's toString method does
of which 1a and 3 are probably what the interviewer is most interested in knowing.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.
- References:
- Re: Interesting Java interview question
- From: Jack
- Re: Interesting Java interview question
- From: Joshua Cranmer
- Re: Interesting Java interview question
- From: Doug Dunn
- Re: Interesting Java interview question
- Prev by Date: Re: Interesting Java interview question
- Next by Date: Re: Multicolored output
- Previous by thread: Re: Interesting Java interview question
- Next by thread: Re: Interesting Java interview question
- Index(es):
Relevant Pages
|
|