Actual and formal argument lists differ in length

posted 8 min read

Today, we're going to discuss a compilation error in Java: "Actual and formal argument lists differ in length". This error is produced when the number of arguments passed in doesn't match the number of parameters defined in the method or constructor. In this study blog, we'll explore what's "Actual and formal argument lists differ in length", why it happens and how to resolve it.

What is "Actual and formal argument lists differ in length" #

First, let's understand what is actual argument and formal argument.

  1. Formal argument: The arguments we define for a method or constructor.
  2. Actual argument: The arguments we pass into a method or constructor.

Let's see an example:


  public static void main(String[] args) {
        int num_1 = 10;
        int num_2 = 20;
        int sum = addition(num_1, num_2);
        }
    
     public static int addition(int a, int b){
        return a + b;
    } 
  

From the above example, a and b is the formal arguments while num_1 and num_2 is the actual arguments that we pass into the method addition.

Now, we've understood the difference between actual argument and formal argument. Let's see another example:


        public static void main(String[] args) {
        int num_1 = 10;
        int num_2 = 20;
        int sum = addition(num_1);
        }
    
     public static int addition(int a, int b){
        return a + b;
    }
  

The compilation error occurs:


  method addition in class NewMain cannot be applied to given types;
  required: int,int
  found:    int
  reason: actual and formal argument lists differ in length
  

Here, we pass in only one actual argument, num_1 but the method, addition actually defines two formal arguments, a and b to work. Let's see another example:


        public static void main(String[] args) {
        int num_1 = 10;
        int num_2 = 20;
        int num_3 = 30;
        int sum = addition(num_1, num_2, num_3);
        }
    
     public static int addition(int a, int b){
        return a + b;
    }
  

The compilation error also occurs:


  method addition in class NewMain cannot be applied to given types;
  required: int,int
  found:    int,int,int
  reason: actual and formal argument lists differ in length
  

Here, we pass in three actual arguments, num_1, num_2, and num_3 while the method, addition only need two formal arguments to work.

So far we've discovered this problem in the method invocation. Let's see some examples of constructor:


public class Student {
    private String first_Name;
    private String last_Name;
    
    public Student(String first_Name, String last_Name){
        this.first_Name = first_Name;
        this.last_Name = last_Name;
    }
}
  

Here, we declare a class, Student, where we need first_Name and last_Name arguments in the constructor to create an instance of Student.


Student student = new Student("Alex");
  

Here is the compilation error:


constructor Student in class Student cannot be applied to given types;
required: String,String
found:    String
reason: actual and formal argument lists differ in length
  

Let's move on to the next section to see why it occurs.

Causes #

From the above examples, we can see that this compilation error occurs when the number of actual arguments we pass into the method or constructor doesn't match the number of formal arguments we define for the method or constructor. As long as there's mismatch between the number of actual arguments and the number of formal arguments, this error will always be produced. Don't fret; it can be simply solved, let's move on to the next section:

Solution #

You may guess the solution. Yes, you just need to remember the main concept while defining and using the methods / constructors:

The actual and formal argument lists should always be same in length

What means? Before using the methods or constructors, you should check the number of formal arguments defined for a method or constructor. When you want to invoke a method or initiate an instance of object using constructor, make sure the number of actual arguments passed in is same as the number of formal arguments.


public static void main(String[] args) {
        int num_1 = 10;
        int num_2 = 20;
        int num_3 = 30;
        int sum = addition(num_1, num_2, num_3);
        System.out.println(sum);
        }
    
     public static int addition(int a, int b, int c){
        return a + b + c;
    }
  

This is the output:


60
  

We can either increase / decrease the number of formal arguments defined or the number of actual arguments passed in. Just to make sure both are having the same length.

Tip For a Class, if you didn't override its constructor, the constructor has no any formal arguments

public class Student {
    private String first_Name;
    private String last_Name;

    public String getFirst_Name() {
        return first_Name;
    }

    public void setFirst_Name(String first_Name) {
        this.first_Name = first_Name;
    }

    public String getLast_Name() {
        return last_Name;
    }

    public void setLast_Name(String last_Name) {
        this.last_Name = last_Name;
    }
}
  

I define a class, Student without overriding its default constructor.


Student student = new Student();
  

The compilation error will not occur and we can assign value to the variable, student using setter method in the class.

The Conclusion #

Thanks for sticking with this blog until the end. In this lesson, we've learned about what's "Actual and formal argument lists differ in length" in Java. Besides, we've known what is the causes of this compilation error and how to solve it simply. Just to remind again, we should always make sure the formal arguments and actual arguments have the same length. Otherwise, this error will be thrown during compilation.

The Reference #

You may go through this reference for more information:

  1. Constructors: https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

1 Comment

0 votes

More Posts

Understanding Basic Data Structures for Web Development

MasterCraft - Feb 16

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelskiverified - Mar 19

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9

Beyond the 98.6°F Myth: Defining Personal Baselines in Health Management

Huifer - Feb 2

Actual Run of Coderive Language for Lazy Array and Loop

Danison Nuñez - Dec 26, 2025
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

11 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!