Forums Register Login

is it really instantiating an abstract class here?

+Pie Number of slices to send: Send
Some time back in a thread i found a post saying

Of corse an abstract class can be instantiated, though only through an anonymous class



So in this code,

are we really instatialing an object of class A? are not we first making an anonymous class which extends A and implements its abstract method and creating an object of that anonymous class?

please clarify.

TIA
+Pie Number of slices to send: Send
You are right, and the post you found is wrong. This is not instantiating an abstract class.
+Pie Number of slices to send: Send
 

Originally posted by subhajit paul:
are we really instatialing an object of class A? are not we first making an anonymous class which extends A and implements its abstract method and creating an object of that anonymous class?

I presume instatialing should be spelt instantiating!

You are actually doing both. Try declaring it an an A, and try using the instanceof operator on it . . . you should get "true."
+Pie Number of slices to send: Send
That does sound like what I might say; if it was me, I am sorry about the mistake.
+Pie Number of slices to send: Send
 

Originally posted by Campbell Ritchie:
That does sound like what I might say; if it was me, I am sorry about the mistake.


I believe it was you; I can vaguely remember that post.

The anonymous class is a subclass of A without a proper name. I'm saying proper name because it does have a name; in this case the name would be AbstractExample$1.
+Pie Number of slices to send: Send
It was me; I found it last night and can't find it now.

I did actually say "don't know" and "try new A(){};" which is not quite the same as what is being done here.
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 800 times.
Similar Threads
Employee class - Abastract Vs Interface
Anonymous inner class
Anonymous inner classes
Anonymous Inner Class
Abstract class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:36:43.