Interface usage

Interface usage

Easy Java OOP Basics 15 views
Explanation Complexity

Problem Statement

Task: create interface Computation and a class Add that implements it.

Input Format

Two integers a and b

Output Format

Sum of a and b

Example

10 15
25

Constraints

• Use interface

• Class must implement the interface

Concept Explanation

An interface defines a method without body.
Class Add implements that method and provides logic for addition.

Step-by-Step Explanation

1.Create interface Computation.

2.Declare method compute(int a, int b).

3.Create class Add that implements Computation.

4.Override compute() method.

5.Return a + b.

Concept Explanation

An interface defines a method without body.
Class Add implements that method and provides logic for addition.

Step-by-Step Explanation

1.Create interface Computation.

2.Declare method compute(int a, int b).

3.Create class Add that implements Computation.

4.Override compute() method.

5.Return a + b.

Input / Output Format

Input Format
Two integers a and b
Output Format
Sum of a and b
Constraints
• Use interface

• Class must implement the interface

Examples

Input:
10 15
Output:
25

Example Solution (Public)

Java
static interface Computation{int compute(int a,int b);}static class Add implements Computation{public int compute(int a,int b){return a+b;}}

Official Solution Code

static interface Computation{int compute(int a,int b);}static class Add implements Computation{public int compute(int a,int b){return a+b;}}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.