next


Java Online Compiler
Method Overloading
Polymorphism


class Poli
{
void walk()
{
System.out.println("he is walking normally");
}
void walk(String style)
{
System.out.println("he is walking "+style+" Style");
}

void walk(String style,String nature)
{
System.out.println("he is walking "+style+" Style in the "+nature);
}
void walk(String style,String nature,int speed)
{
System.out.println("he is walking "+style+" Style in the "+nature+" with "+speed+ "km/h");
}
}
class Overloading
{
public static void main(String args[])
{
Poli p=new Poli();
p.walk();
p.walk("Cat");
p.walk("Cat","Rain");
p.walk("Cat","Rain",45);
}
}


							
							

Constructor Overloading

class Poli
{
Poli()
{
System.out.println("he is walking normally");
}
Poli(String style)
{
System.out.println("he is walking "+style+" Style");
}

Poli(String style,String nature)
{
System.out.println("he is walking "+style+" Style in the "+nature);
}
Poli(String style,String nature,int speed)
{
System.out.println("he is walking "+style+" Style in the "+nature+" with "+speed+ "km/h");
}
}
class Overloading
{
public static void main(String args[])
{
Poli p=new Poli();
Poli p2=new Poli("Cat");
Poli p3=new Poli("Cat","Rain");
Poli p4=new Poli("Cat","Rain",45);

}
}