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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:25:12+00:00 2026-05-25T20:25:12+00:00

public class A{ public A(int[] a){} } public class B extends A{ public B(double[]

  • 0
 public class A{
      public A(int[] a){}
 }

 public class B extends A{
      public B(double[] b){
           super({b.length});  //ERROR
      }
 }

I want to be able to compile the code above. To clarify, I have class A and B that extends it. Class A does not have an empty parameter constructor. If I don’t put a call to super in Class B’s constructor on the first line, it will try to call super(), which doesn’t exist. But, I want to call super(int[] a) instead. I want to do this by taking the length of a given double array and sending it as an array with length 1. It does not let me do this because apparently you can’t declare an array like that, and if I were to declare it on a separate line it would call super() first and that won’t work.

Is there any way to declare an int[] on the fly like that? Or are the only solution here to either make a constructor for A with no parameters or make my own function that returns an int[]?

(Don’t ask why I want to send it as an array like that.)

  • 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-25T20:25:12+00:00Added an answer on May 25, 2026 at 8:25 pm

    If you insist on not asking why…

    You could make the array, assign the first and only element and send it.

    public class B extends A{
          public B(double[] b){
               int[] arr = new int[1];
               arr[0] = b.length;
               super(arr);  // broken, super must be first.
          }
    }
    

    This means you must have a one line solution. Luckily, Java provides an in-line way to make a series of elements into an array at compile time.

    public class B extends A{
          public B(double[] b){
               super(new int[]{b.length});  // FIXED
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class JFrameWithPanel extends JFrame implements ActionListener, ItemListener { int packageIndex; double price; double[]
public class PlayText extends Thread { private int duration; private String text; private PlayerScreen
public class MaxHeap<T extends Comparable<T>> implements Heap<T>{ private T[] heap; private int lastIndex; public
I got the following: class A{ int foo; } class B extends A{ public
class A{ A(int x){} } class B extends A{ B(int x){} public static void
class Scr extends MainScreen { public Scr() { TableLayoutManager outerTable = new TableLayoutManager(new int[]
The below code in Java throws Null pointer exception. public class New{ int i;
Inside public class IAmHere extends Activity implements LocationListener { i have @Override public void
Here's my current code: public class MallMapActivity extends Activity { private final static String
I have written a default table render as follows: public class CustTableRenderer extends DefaultTableCellRenderer{

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.