Wednesday 27 January 2016

Java Tutorial : Java Polymorphism(version4)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=R-LO5JjAtBM&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Polymorphism(version4)
Java Tutorial : Java Polymorphism(version4)
Java Tutorial : Java Polymorphism(version4)
Java Tutorial : Java Polymorphism(version4)
Java Tutorial : Java Polymorphism(version4)
Java Tutorial : Java Polymorphism(version4)
OverloadingTest.java
public class OverloadingTest
{

    public int add(int x, int y)
    {
        return x + y;
    }

    public int add(int x, int y, int z)
    {
        return x + y + z;
    }

    public int add(double x, int y)
    {
        return (int) x + y;
    }

    public int add(int x, double y)
    {
        return x + (int) y;
    }

    public static void main(String[] args)
    {
        OverloadingTest overloadingTest = new OverloadingTest();
        System.out.println(overloadingTest.add(4, 3));
        System.out.println(overloadingTest.add(2, 3, 4));
        System.out.println(overloadingTest.add(2.5, 3));
        System.out.println(overloadingTest.add(9, 3.4));
    }

}
Output
7
9
5
12
OverriddenTest.java
class Vehicle
{
    public void move()
    {
        System.out.println("Vehicles can move");
    }

}

class Car extends Vehicle
{
    public void move()
    {
        System.out.println("Car can move very fast");
    }

}

public class OverriddenTest
{

    public static void main(String[] args)
    {
        Vehicle vehicleRef = new Car();

        vehicleRef.move(); // prints Car can move very fast

        vehicleRef = new Vehicle();

        vehicleRef.move(); // prints Vehicles can move"
    }

}
Output
Car can move very fast
Vehicles can move
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/PolymorphismDemo_V4_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/PolymorphismDemo_V4_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/527ec09d8e1fd3cdfc42e1a5df2ff8d97e615036/BasicJava/PolymorphismDemo_V4_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • 1 comment: