Java Constructor

class Add
{

int add (int x , int y)
{
return (x+y);
}

}

class FloatAdd extends Add
{

float add(float x, float y)
{
return (x+y);
}

}
class Test
{

public static void main(String [] args)
{
Add a = new Add();
FloatAdd addObj = (FloatAdd) a;
System.out.println("Result : "+addObj.add(10, 20));
}

}

What would be output?

Options
- 30.00
- 30
- Complie error
- Runtime Exception


CORRECT ANSWER : Complie error

Discussion Board
Runtimetime exception

Exception in thread "main" java.lang.ClassCastException: Add incompatible with FloatAdd

Manish Malaviya 11-20-2014 06:03 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement