filmov
tv
JAVA : What is method overloading in Java? SDET Automation Testing Interview Questions & Answers

Показать описание
JAVA : What is method overloading in Java?
SDET Automation Testing Interview Questions & Answers
We will be covering a wide range of topics including QA manual testing, automation testing, Selenium, Java, Jenkins, Cucumber, Maven, and various testing frameworks.
JAVA : What is method overloading in Java?
Method overloading in Java is the ability to define multiple methods with the same name in a class, but with different parameters. The compiler distinguishes between the different methods based on the number, type, and order of the parameters. Here's an example of method overloading in Java:
public class MathUtils {
public static int add(int a, int b) {
return a + b;
}
public static double add(double a, double b) {
return a + b;
}
}
public class Main {
public static void main(String[] args) {
}
}
This defines a class called MathUtils with two overloaded methods called add. One takes two integers as parameters and returns their sum as an integer, while the other takes two doubles as parameters and returns their sum as a double. In the main method, both versions of the add method are called with different types of parameters, producing the following output:
Output =
8
6.2
SDET Automation Testing Interview Questions & Answers
We will be covering a wide range of topics including QA manual testing, automation testing, Selenium, Java, Jenkins, Cucumber, Maven, and various testing frameworks.
JAVA : What is method overloading in Java?
Method overloading in Java is the ability to define multiple methods with the same name in a class, but with different parameters. The compiler distinguishes between the different methods based on the number, type, and order of the parameters. Here's an example of method overloading in Java:
public class MathUtils {
public static int add(int a, int b) {
return a + b;
}
public static double add(double a, double b) {
return a + b;
}
}
public class Main {
public static void main(String[] args) {
}
}
This defines a class called MathUtils with two overloaded methods called add. One takes two integers as parameters and returns their sum as an integer, while the other takes two doubles as parameters and returns their sum as a double. In the main method, both versions of the add method are called with different types of parameters, producing the following output:
Output =
8
6.2
Комментарии