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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:29:19+00:00 2026-06-14T19:29:19+00:00

class A { A(int i){ System.out.println(A(int)); } } class B1 extends A{ public static

  • 0
class A {
     A(int i){    
        System.out.println("A(int)");
     }
 }

class B1 extends A{
    public static void main(String args[]){
        A ob=new A(2);  
    }
}
  • 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-14T19:29:20+00:00Added an answer on June 14, 2026 at 7:29 pm

    You have declared a 1-arg constructor in class A. So, compiler does not provide a default 0-arg constructor.

    Now, in class B1, you have not defined any constructor, so compiler adds a default 0-arg constructor in that class, which looks like this: –

    public B1() {
        super();
    }
    

    As you can see, Compiler adds a super() call to invoke the 0-arg constructor of the super class, which is class A, in this case.

    Now, since your class A, does not have any 0-arg constructor, hence the error.


    So, either you can add a 0-arg constructor in your class A: –

    public A() {
    
    }
    

    This will solve the issue.


    Or, add a 0-arg constructor in your class B1 explicitly, and add a super() call to the 1-arg constructor of class A: –

    public B1() {
        super(0);  // Or any value
    }
    

    But, the problem in the 2nd solution will be that, from every constructor in your class B1, you would have to invoke the 1-arg constructor of class A explicitly. As soon as you miss one, you will get a compiler error immediately.

    So, I would suggest to go with the 1st option. Add a 0-arg constructor in class A. And you are all good.

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

Sidebar

Related Questions

class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
import java.util.Scanner; public class Main extends Hashmap{ public static void main(String[] args) { Hashmap
public class Animal{ int n = 5; public static void main(String[] args) { Animal
class A{ int a=10; public void show(){ System.out.println(Show A: +a); } } class B
import java.util.*; public class Test { public static void main(String[] args) { List db
class Base { int i = 99; public void amethod() { System.out.println(Base.amethod()); } Base()
Please find below is the sample code:- class ExtendMe{ public void printV(int x){ System.out.println(x);
I have the below code. public class Test { public static void main(String args[])
class C{ static int f1(int i) { System.out.print(i + ,); return 0; } public
Here is my code class Glyph { void draw() { System.out.println(Glyph.draw()); } Glyph(int i)

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.