Java Inheritance
Submissions: 1257   Accuracy:

68.58%

  Difficulty: School   Marks: 0
*School Problem's Submission isn't counted in score!

Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allow to inherit the features(fields and methods) of another class.

Consider the following class cls1:
class cls1
{

    void add(int p,int q){
        System.out.println(p+q);
    }
}

There is another class cls2 which extends class cls1:
class cls2 extends cls1
{
    void mul(int p,int q)
    {
        System.out.println(p*q);
    }
}

So we can make object of a class cls2, which can use both mul and add methods. Main function is already created in the editor and instance of cls2 is also made. So the task is to add a method in class cls2 naming task() which will take 2 parameters as input i.e. a and b and print the sum of their squares i.e a2+b2. Changes in the main function has been made already.

Input:
The input line contains T, denotes the number of testcase. Each testcase contains one line containing a and b separated by space.

Output:
For each testcase in new line, print the required answer.

Constraints:
1 <= T <= 100
1 <= a, b <= 103

Example:
Input:

1
2 4

Output:
6
8
20

Explanation:
Testcase 1: Output contains 3 lines:
In 1st line sum of two numbers is printed from the method add().
In 2nd line multiplication of two nos is printed from the method mul().
In 3rd line sum of the sqaures of the two nos is printed using your created method task().

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: S_A
Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.