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 6733771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:48:35+00:00 2026-05-26T10:48:35+00:00

I have the following example classes in Java: public class A { } public

  • 0

I have the following example classes in Java:

public class A { }

public class Super {
    protected Super() { }
    public Super(A a) { }
}

public class Sub extends Super { }

public class Consumer {
    public Consumer() {
        Sub sub = new Sub(new A()); //compiler error
    }
}

The compiler error states that the arguments cannot be applied to the default constructor in Sub, which is perfectly understandable.

What I’m curious about is the rationale behind this decision. Java generates the default empty constructor in Sub; why can’t it call it behind the scenes in this case? Is this primarily a case of sane hand-holding, or is there a technical reason?

EDIT

I’m aware that this is a language limitation. I’m curious about why it is a language limitation.

EDIT 2

It seems that, as is often the case, I was too close to the code I was actually working in to see the big picture. I’ve posted a counter-example in the answers below that shows why this is a Bad Thing®.

  • 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-26T10:48:35+00:00Added an answer on May 26, 2026 at 10:48 am

    I think it’s an issue of both readibility and not assuming intent. You say

    Java generates the default empty constructor; why can’t it call it behind the scenes in this case?

    Yet to me, it would make much more sense for Java to implicitly call the Super(A) constructor “behind the scenes” than to call the Super() constructor, disregarding A.

    And there you have it. We already have two disparate assumptions about what should (or could) happen in this case.

    One of the Java language’s core principles is transparency. As much as possible, the programmer should be able to see by looking at the code what will happen, sometimes at the expense of convenience or magic at the syntax level.

    A parallel tenet to that is not assuming intent: in cases where the programmer’s intentions seem ambiguous, the Java language will sometimes favour a compile error rather than automatically chosing a default through some (arbitrary or otherwise) selection algorithm.

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

Sidebar

Related Questions

As a simplified example, I have the following data classes: public class Employee {
Let's have a following example: public class X { } public class Y {
I have the following classes. public class B { public A a; public B()
Consider the following example. I have an interface MyInterface, and then two abstract classes
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have the following example code: class A(object): def __init__(self, id): self.myid = id
I have create following java file,compile it and got .class file. import java.io.*; import
I have the following JPA entity classes (example case). A House belongs on a
I have the following example, compiled in VS2005, warning level 4: int main(int argc,
I have the following example of reading from a buffered reader: while ((inputLine =

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.