Google+ Followers

Connect

Get Updates Via Email

Enter your email address:

Delivered by FeedBurner

Monday, 11 November 2013

Java Program: Down casting Inheritence

Program

public class downcasting {
   public static void main(String[] args)
    {
     fordd f;
     benzz b;
     BMWw bm;
     carr c,cc,ccc;
     c=new fordd();
     cc=new benzz();
     ccc=new BMWw();
     f=(fordd)c; // downcasting or narrowing or specialization
     b=(benzz)cc;
     bm=(BMWw)ccc;
     f.car();
     b.car();
     bm.car();
    }
}
class carr
{
    void car()
    {
        System.out.println("This super class car method");
    }
}
class fordd extends carr
{
    void car()
    {
        System.out.println("This sub class Ford car method");
    }
}
class benzz extends carr
{
     void car()
    {
        System.out.println("This sub class Benz car method");
    }
}
class BMWw extends carr
{
     void car()
    {
        System.out.println("This sub class BMW car method");
    }

}

Output



1 comment :

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete

Share this to your friends