Write a program as an example of type casting for data type

Program:

//define class in the program
//Q1.can we change the integer value direct to byte means exact value even type //conversion can be used
//Q2.try by inc or dec the int value

class A
{
    //static int x=10;
    public static void convert()
    {
        //data type of variable
        long k=244;
        System.out.println(k);
        // type casting of data type
        int a=(int)k;
        System.out.println(a);
       
        //type casting of data type
        int i=12;
        byte b=(byte)i;
       
        //print function
        System.out.println(i);
        System.out.println("value of byte variable is="+b);
    }
}

//define class in which main method of function is calling
class Example4
{
    //int x=10;
    public static void main(String args[])
    {
        A.convert();
    }
}



Sample output:


Post a Comment

Previous Post Next Post