Ques. Define the class Interchange which will contain the overloaded definitions of the swap function , which will be used for swapping integers, double and character type values?
class Interchange
{
void swap(int
a,int b)
{
int
c;
c=a;
a=b;
b=c;
System.out.println(“a=
“ + a + “ b = “ + b);
}
void swap(char
a,char b)
{
char
c;
c=a;
a=b;
b=c;
System.out.println(“a=
“ + a + “ b = “ + b);
}
void swap(double
a,double b)
{
double
c;
c=a;
a=b;
b=c;
System.out.println(“a=
“ + a + “ b = “ + b);
}
}
class InterDemo
{
public static
void main(String args[ ])
{
Interchange
ob=new Interchange();
ob.swap(5,6);
ob.swap(‘d’,’e’);
ob.swap(5.23,6.98);
}
}
Comments
Post a Comment