Wednesday 27 January 2016

Java Tutorial : Java Runtime Polymorphism(version1)


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

Click the below Image to Enlarge
Java Tutorial : Java Runtime Polymorphism(version1) 
Java Tutorial : Java Runtime Polymorphism(version1) 
Vehicle.java
public class Vehicle
{
    public void drive()
    {
        System.out.println("Driving vehicle ...");
    }
}

class Car extends Vehicle
{
    @Override
    public void drive()
    {
        System.out.println("Driving car...");
    }
}

class Truck extends Vehicle
{
    @Override
    public void drive()
    {
        System.out.println("Driving truck...");
    }

    public void load()
    {
        System.out.println("Loading truck...");
    }
}
RunTimePolymorphismDemo.java
public class RunTimePolymorphismDemo
{

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

        vehicleRef = new Car();
        vehicleRef.drive();

        vehicleRef = new Truck();
        vehicleRef.drive();

        // Compile time error
        // vehicleRef.load();

        Truck truckRef = new Truck();
        truckRef.load();
    }

}
Output
Driving vehicle ...
Driving car...
Driving truck...
Loading truck...

Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/PolymorphismDemo_Runtime_App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2ec4ef86a93fffce49e990abd3b81708f562c200/BasicJava/PolymorphismDemo_Runtime_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
  • 2 comments:

    1. Hi, I read your whole blog. This is very nice. Good to know about the career in qa automation is broad in future. We are also providing various Java Training, anyone interested can Java Training Online for making their career in this field .

      ReplyDelete