Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3792500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:37:54+00:00 2026-05-19T12:37:54+00:00

It is not possible to create an object by directly calling the constructor of

  • 0

It is not possible to create an object by directly calling the constructor of an abstract class. The constructor of an abstract class can be called only from a derived class. It therefore seems to me that constructors of an abstract class must be either protected or package-private (the latter for the unusual cases of restricting use of a constructor to derived classes within the package). Yet Java allows the constructor of an abstract class to be public.

Are there any circumstances in which it is useful to declare the constructor of an abstract class to be public, rather than protected or package-private?

This is not quite a duplicate of the question “Abstract class constructor access modifier“: clearly you can declare a constructor to be public; I want to know whether there is ever any good reason to do so. It seems to me that there is not. I see that C# has a similar peculiarity.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:37:55+00:00Added an answer on May 19, 2026 at 12:37 pm

    The answer is the same for java:

    THere’s no reason for a public constructor for an abstract class. I’d assume that the reason that the compiler doesn’t complain is as simple that they just didn’t spend time covering that since it really doesn’t matter if it’s public or protected. (source)

    You can’t call a constructor of an abstract class from anything other than a direct subclass.

    So adding a special rule for access modifiers of constructors of abstract classes wouldn’t add something useful to the language.


    One thing that looks like an exception from this rule – if the abstract class only defines a default constructor, then the subclass does not have to implement a constructor: this is legal:

    public abstract class A {
      public A() {}
    }
    
    public class B extends A {}
    

    So we can create a B by calling new B() – but note, that we still create a B and not an A. And, again, it doesn’t matter if the constructor in A is public or protected. It just shouldn’t be private, but the compiler will notice and complain…

    Actually we invoke an “invisible” public default constructor on B which does a simple super() call…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: declare property as object? in java you can create an object directly
Is it possible to create a trigger that will not be in a transaction?
Is it possible to create an sql statement that selects the week number (NOT
Is it possible to create LIGHTWEIGHT transactions using TransactionScope() with SQL2000? Or if not,
This is probably not possible, but I have this class: public class Metadata<DataType> where
Someone on IRC told me I could create objective c objects directly from plist
I am wondering if it is possible to have JAXB not to create Java
It is not possible to check out a single file. The finest level of
It is not possible to fire an event in C# that has no handlers
As far as i know it is not possible to do the following in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.