1. Consider the following program, what is the output? (5 marks)
class overload
{
int x;
double y;
void add(int a , int b)
{ x = a + b; }
void add(double c , double d)
{ y = c + d; } overload()
{ this.x = 0;
this.y = 0;
}
} class Overload_methods
{ public static void main(String args[])
{
overload obj = new overload();
int a = 2; double b = 3.2;
obj.add(a, a);
obj.add(b, b);
System.out.println(obj.x + " " + obj.y);
SOLUTION
The following is the output of the program:
4 6.4
Explanation
This is beacuse x is the sum of the two integers and it is given integer 2 i.e 2+2 = 4
y is the sum of two double vlaues and it is given 3.2 i.e 3.2 + 3.2 = 6.4
Comments
Leave a comment