Rules to call Parameterized method:-
The length of actual and formal arguments should be same.
The corresponding datatype of actual and formal arguments should be same.
If same type is not available then compiler tries to do widening.
Suppose widening is also not possible then we get compile time error (CTE).
Program:
- class A1
- {
- //1
- public static void test( )
- {
- System.out.println("No-args");
- }
- //2
- public static void test(int a)
- {
- System.out.println("int");
- }
- //3
- public static void test(double a)
- {
- System.out.println("double");
- }
- public static void main(String [] args)
- {
- test('b');
- }
- }
Output:
int
Merhod Recursion:-
Method is calling itself.
Executing same set of statements repeatedly is known as Method Recursion.
Recursive call statement.
The statement which is responsible for recursion.
Program:
- class A2
- {
- public static int badam( )
- {
- System.out.println("Hello");
- badam( ); //Recursive called statement
- System.out.println("Bye");
- }
- public static void main(String [] args)
- {
- System.out.println("MB");
- badam( ); //Method calling statement
- System.out.println("ME");
- }
- }
Output:
MB
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Get stack overflow error
Tracing:
Interview question
When do we get stack overflow error ?
>>>During Method Recursion Error <> It is an example of runtime error.
0 Comments