Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

abstact private

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,
I was wondering why is abstract private allowed for inner class.Is it useful in any way?

Its not even allowed for the methods,correct?

Why is it allowed for inner classes???
Thanks........
 
author
Posts: 23926
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why is it allowed for inner classes???



Why not?

Abstract methods don't make sense because polymorphism don't apply to private methods -- so having an abstract method that can't be overridden (ie. implemented) doesn't make sense.

There is no such issue for private abstract classes.

Henry
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason why it's allowed for inner classes to be both abstract and private is because you could define a concrete subclass inside the enclosing class. In contrast, instance methods can't be both abstract and private, because the point of an abstract method is to be overridden in a subclass (but private methods can't be overridden.)
 
rhett howard
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys!!
That makes sense!! I wasn't really thinkin' about polymorphism inside a class.


Btw, If an inner class is abstract, does it make the enclosing class abstract too like with the instance methods?
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rhett howard wrote:Thanks guys!!
That makes sense!! I wasn't really thinkin' about polymorphism inside a class.


Btw, If an inner class is abstract, does it make the enclosing class abstract too like with the instance methods?


Rhett, I don't think so. When a class has any abstract methods that makes the class abstract, because instantiating an object of such a class would make no sense (as it would have instance methods attached to it which would be undefined.) But when a class has an abstract inner class inside it, that doesn't make the class abstract. Take a look at this example code:

 
rhett howard
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ruben!!

 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem Rhett. If you are interested in inner classes you can do a search in the forums. There are quite a few posts that are very interesting.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ruben Soto wrote:

rhett howard wrote:



Hi Ruben,
your instantiating the abstract inner class by using the outer class object. In that your implementing the abstract method.here my question is all inner class abstract methods must be implemented like that only???
i mean with in the braces used while instantiating abstract inner class.

Thanks®ards,
Nagaraju.

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you can just implement new class directly, for example like this:


 
NagarajGoud uppala
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tomas
Thanks..
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for answering the question. Any class that you can extend via an anonymous inner class you can extend via a regular member class. I just thought I would have to type less code that way (I'm lazy.)
 
rhett howard
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah , I was reading this article
http://mindprod.com/jgloss/anonymousclasses.html

and it says :
If you want to baffle those maintaining your code, wags have discovered javac.exe will permit anonymous classes inside static init code and static methods, even though the language spec says than anonymous classes are never static. These anonymous classes, of course, have no access to the instance fields of the object. I don’t recommend doing this. The feature could be pulled at any time.


I don't know when this article is written, but is this feature already pulled? ...........
 
rhett howard
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I am wondering watz wrong with anonymous classes inside a static method?..

Ruben, you just used one inside the static main method , rite?.......

It didn't baffle me at all!!!


Thanks.......
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't read the whole article, but based on the quote that you provide I think that the person that wrote that is a little confused. It's true that anonymous inner classes are never static classes (because static classes are technically not inner classes.) But just because you instantiate an anonymous inner class inside a static method, it doesn't make the class static. The same way that instantiating Integer inside a static method doesn't make Integer a static class. You can also define a regular local inner class inside a static method, and that doesn't make it a static class. It's true that it won't be able to access any instance members of the enclosing class unless it is via an reference to an instance of the enclosing class (because inside a static method there is no implied instance.) But you can only define static classes at the top level of the enclosing class (not inside any blocks.)
 
rhett howard
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought he was confused too....

thanks......
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem, Rhett. For the record, here is the classification of classes:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic