Consider the following program, what is the output? (2 marks)
class overload
{
int x;
double y;
void prod(int n)
{
for (int i=1;i<n;i++)
x=x*i
}
void prod(int n, int m)
{
for (int i=n;i<m;i++)
y=y*i
}
overload()
{
this.x = 1;
this.y = 1;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int n = 2;
int m = 4;
obj.prod(n);
obj.prod(n,m);
System.out.println(obj.x + " " + obj.y);
}
}
output is: 1 6
Comments
Leave a comment