follow

Saturday, 6 July 2013

POLYMORPHISM : JAVA Programming by "Gopal Krishna"

Overloading :

class shona 

{

public int add(int a,int b)

{

return(a+b);

}

public float add(float a,float b)

{

return(a+b);

}

}

class guru 

{

public static void main(String arg[])

{

shona h=new shona();

System.out.println("the sum="+h.add(8,88));

System.out.println("the sum="+h.add(2.5f,3.6f));

}

}


Overwriting  :


class xyz
{
public void disp()
{
System.out.println("hi");
}
}
class xyz1 extends xyz
{
public void disp()
{
System.out.println("how are ");
}
}
class xyz2 extends xyz
{
public void disp()
{
System.out.println("khana kha k jana");
}
}
class guru
{
public static void main(String args[])
{
xyz x= new xyz();
x.disp();
xyz y= new xyz1();
y.disp();
xyz z= new xyz2();
z.disp();
}
}

No comments:

Post a Comment