Write a program in java to demonstrate downcasting?

Downcasting (Output – It gives Error)

class DownCasting

{

                public static void main(String arg[])

                {

                                float f=12.56;

                                System.out.println(f);

                }

}
DownCasting (Error)
Downcasting

class DownCasting

{

                public static void main(String arg[])

                {

                                float a=(float)12.56;

                                float b=13.58f;

                                System.out.println(a);

                                System.out.println(b);

                }

}
DownCasting.PNG
, , ,

Leave a Reply