• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract classes and methods and access specifiers

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I'd like to know if

1. Abstract classes can have an access specifier or not? Why or why not?

2. Abstract methods can have an access specifier or not? Why or why not?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll say you should try your "can" questions and then ask us in detail "why" questions.
 
Sid Kar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I will try it in a compiler and get back to you.
 
Sid Kar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I tried and found out the following:

1. Abstract classes can be made public or package, but not private or protected.

2. Abstract methods can be made public or package or protected, but not private.

Please can somebody tell me why?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sid Kar wrote:
1. Abstract classes can be made public or package, but not private or protected.


https://coderanch.com/t/410134/java/java/private-protected-class

Sid Kar wrote:
2. Abstract methods can be made public or package or protected, but not private.


private method is implicitly final. so it wont make any sense to mark it as abstract, since concrete subclasses have to override abstract method.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write down what an abstract method is for, and it should become obvious why it cannot have a private modifier (not “specifier”).
Work out what private and protected mean and try to work out what they would mean for top‑level classes. then you can see why the only access modifier permissible for a top‑level class is public.
 
Sid Kar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thanks guys.
 
reply
    Bookmark Topic Watch Topic
  • New Topic