• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Cannot create a concrete sub-class of a public abstract class, in another package

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While trying out some stuff for examination, came across a scenario which defeats the public keyword to a certain extent. My 2 cents, check out the following code




Well not sure how everybody would have guessed it but for the first time i wud hv thot it prints Hi. But actually the code doesn't compile, as the abstract method is default.

 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah even though the class is visible(can extend or create instances), the member method is not visible outside the package. Also even if it was visible(public or protected), your code will not compile as you have not overridden the abstract method.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags instead of quote tags for source code.
 
Rushabh Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper Young wrote:Please use code tags instead of quote tags for source code.



My bad. Fixed it.
 
Rushabh Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitish Bangera wrote:Yeah even though the class is visible(can extend or create instances), the member method is not visible outside the package. Also even if it was visible(public or protected), your code will not compile as you have not overridden the abstract method.



Nitish my bad, about me() method was not intended. Have rectified & put up the original code. Just that used me() for testing locally
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still it won't work as you are making the overridden method access modifier more restrictive(from protected or public to default)
 
Rushabh Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitish Bangera wrote:Still it won't work as you are making the overridden method access modifier more restrictive(from protected or public to default)



not really... its default only... like the one in parent
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If its default, then its not visible to the class outside the package. You are creating a new method here for the subclass. I suppose this will be running fine now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic