Why does a main() function in java doesn't throw a 'actual and formal parameters mismatch error' even if the program doesn't involve getting input from the command line.This is a sample program where the near() function has same number of actual and formal parameters and compiles without any error,whereas the far() method throws a parameter mismatch error since I haven't given any parameters while calling it.
import java.util.Scanner;
import java.io.*;
class Prime
{
void near(int x,int y)
{
System.out.println(x+y);
}
void far(int a,int b)
{
System.out.println(a+b);
}
public static void main(String args[])
{
Prime n=new Prime();
n.near(5,4);
n.far();
}
}
C:\Users\hcl\Desktop>javac Prime.java
C:\Users\hcl\Desktop>javac Prime.java
Prime.java:20: error: method far in class Prime cannot be applied to given types
;
n.far();
^
required: int,int
found: no arguments
reason: actual and formal argument lists differ in length
1 error