Menu
Topics Index
...
`

Creating Methods with return statement


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Methods with return statement
What is the output of the following program?
class Top {
    public static int area(int l) {
        return l * l;
    }
}
class Bottom extends Top {
    public static double area(int l) {
        return l * l;
    }
    public static double area(int l, int b) {
        return l * b;
    }
    public static double area(double b) {
        return 4 * b;
    }
}
public class PolyMorphism {
    public static void main(String... k) {
        System.out.println(Top.area(5) + " " + Bottom.area(2) + " " + Bottom.area(3) + "" + Bottom.area(2, 4));
    }
}

A. 25 4 12 8
B. 25 4.0 12.0 8.0
C. 25 4.0 9.0 8.0
D. Compilation Error
E. Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

c is the answer its just the basic implementation of polymorphism

Posted by Karteek Paruchuri    2013-08-12 08:30:37


D compilation error  return type of area in Bottom does not matches

Posted by Yeshu Yeshwanthi    2013-08-12 08:32:58


C is the corect answer because we donot get any compile time erroe and here it is method hiding but not over riding and the methods execute as usually and print output as 25 4.0 9.0 8.0

Posted by Ram Reddy Bitla    2013-08-12 08:34:34


ans should be D: compilation error.. bcoz the the return type of area method with one int parameter are different in top and bottom classes

Posted by Pramod Jain    2013-08-12 15:31:45


Congratulations Yeshu Yeshwanthi. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-08-13 03:36:46


thank you Merit Campus  i got recharge

Posted by Yeshu Yeshwanthi    2013-08-13 14:51:34


© meritcampus 2019

All Rights Reserved.

Open In App