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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:33:56+00:00 2026-06-03T16:33:56+00:00

For example I have this: class A{ private int mine = 0; //Some field…

  • 0

For example I have this:

class A{
    private int mine = 0; //Some field...
    public A(int a){mine+=a; /*Some operation1...*/}
}


class B extends A{
    private int mine = 0; //Some field...
    public B(int a){mine-=a; /*Some operation2...*/}
}

and I get:

error: constructor A in class A cannot be applied to given types;
    public B(int a){}
    required: int
    found: no arguments
    reason: actual and formal argument lists differ in length
    1 errors

I don’t understand the error? What is telling me to do?

Though, the code works if Constructor of “A” has no arguments.
But I need to do the Operation1 (aka mine+=a;), so I need A’s arguments, but then I fail.

I’m closed in this magic circle. What shall I do?

  • 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-06-03T16:33:58+00:00Added an answer on June 3, 2026 at 4:33 pm

    The first instruction of every constructor is always to invoke one of its superclass constructor. If you don’t do it explicitely, the compiler inserts this instraction for you. The constructor

     public B(int a) {
         mine-=a; 
         /*Some operation2...*/
     }
    

    is thus equivalent to

    public B(int a) {
        super(); // invoke the no-arg super constructor
        mine-=a; 
        /*Some operation2...*/
    }
    

    Since A doesn’t have a no-arg constructor, the compilation fails. In this case, you must explicitely invoke one of the super constructors:

    public B(int a) {
        super(a);
        mine-=a; 
        /*Some operation2...*/
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example we have code class MyClass { private: int data; public: int getData()
Let's consider this example : public class Shared { private int attribute; public Shared()
I have this example: public class Inheritance { public static class Animal { public
Let's say I have this code: class Score { public Update(int score) { update
let's assume we have the following code: public class TestScope { private int a
I have this class used in the API demos: public class TextToSpeechActivity extends Activity
Let's say I have this program: class Foo { public: unsigned int bar ()
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
Say I have a class ObjectA (a view controller for example), that does this
For example i have this xml. I need to get value of parameter val

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.