Java Override
Submissions: 1593   Accuracy:


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

In any object-oriented programming language, Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.

Consider the following parent class :

class Parent
    void show(int p)
     System.out.print(p+" ");
    void print(int q){
        System.out.print(q+" ");

Also given a class named child which inherits from Parent class 

class Child extends Parent
    void show(int p) { System.out.print(p+" "); }

Your task is to create a method named print (which takes one integer as input ) in class Child which overrides the method print of the Parent class such that its prints the square of the input integer. In Main function instance of both classes are made and all methods are called in the editor.

The first line of input contains an integer T denoting the no of test cases then T test cases follow. First line of each test case contains four integers p,q,r,s.

Print the required output.



1 2 3 4

1 2 3 16

** 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, generate link and share the link here.

to report an issue on this page.