• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of method local inner class being abstract...  RSS feed

 
Vidya Ram
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
A doubt here....
Method local inner class can be abstract. But I fail to think one good reason as to when it can be made use of.
Because even if you make your method local inner class abstract, you will have to write a concrete class inside the same method if you ever want to use (instantiate) it! What's the fun in writing two classes inside the same method (abstract one and then a concrete one just below it??)
I feel such inner classes are there only to confuse the exam takers like me
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy
I have always considered this one of the most absurd and funny things in Java, for *exactly* the reason you mentioned. I'm sure somebody, somewhere, has an interesting and twisty use for it, but it just makes me laugh.
Despite what you've heard the exam does have a basis in reality. Sometimes deliberately tricky things *are* in the exam, but for the most part, if something is considered "trivia" or "something that's legal but that nobody would ever use and which doesn't serve you in any way to know it", then these types of questions were almost always thrown out if one of the exam writers happened to be having a bad day
Of course, some of the *code* in the exam is written in such a way that nobody would ever do it like that in the real world, but the actual THING the exam question is trying to test you on IS considered important.
That's my way of saying that if I were you, I wouldn't worry much about *this* particular thing being in the exam.
Does that make sense? In other words, the exam will throw questions at you that are *written* in a sometimes tricky way, but they aren't trying to see if you know some unbelievably obscure artifact of the language rules.
I see mock exams that have questions like this, and they should be ignored!
cheers,
Kathy
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example taken from Dan Chisholm´┐Żs Study Guide of how an abstract class might be used to form the basis for a set of algorithms.
You could put these class definitions in a method, if that is the only place they are needed.
 
Vidya Ram
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kathy. Yeah, that makes sense to me.
Thanks Marlene, such an idea never came to me. Infact that's is the reason I posted this message to know if really there is a way to use it other than how I thought (just writing an abstract class and a concrete one below it).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!