0
0
Javaprogramming~15 mins

Method overloading in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a method named add that takes two integers and returns their sum.

Java
public int add(int a, int b) {
    return a [1] b;
}
🎯 Drag options to blanks, or click blank then click option
A-
B+
C*
D/
Attempts:
3 left
2fill in blank
medium

Complete the code to overload the add method to accept two double values and return their sum.

Java
public double add(double a, double b) {
    return a [1] b;
}
🎯 Drag options to blanks, or click blank then click option
A*
B-
C+
D/
Attempts:
3 left
3fill in blank
hard

Fix the error in the overloaded method that adds three integers.

Java
public int add(int a, int b, int c) {
    return a [1] b [2] c;
}
🎯 Drag options to blanks, or click blank then click option
A-
B+
C*
D/
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create an overloaded method that concatenates two strings.

Java
public String add(String a, String b) {
    return a [1] b;
}
🎯 Drag options to blanks, or click blank then click option
A+
B-
C*
D/
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to overload the add method for three double values.

Java
public double add(double a, double b, double c) {
    return a [1] b [2] c;
}
🎯 Drag options to blanks, or click blank then click option
A+
B-
C*
D/
Attempts:
3 left