What is the output of the following Java program no. 9?
class Base
{
void method(int a)
{
System.out.println(“Base class method called with integer a = “+a);
}
void method(double d)
{
System.out.println(“Base class method called with double d =”+d);
}
}
class Derived extends Base
{
@Override
void method(double d)
{
System.out.println(“Derived class method called with double d =”+d);
}
}
public class Main
{
public static void main(String[] args)
{
new Derived().method(10);
}
}
Output
Base class method called with integer a = 10
Explanation
The method() is overloaded in class Base whereas it is derived in class Derived with the double type as the parameter. In the method call, the integer is passed.
Recent Posts