Quick actions

cmd+k|ctrl+k

Navigation

Languages

Cast - Review  

Snippet info

Language

Java

Visibility

public

Author

edmarfyelloww

Created

2020-03-12T22:38:28Z

Updated

2020-03-12T22:38:28Z

class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        
        /*
        
        Casting in Java. Casting is the process of making a variable behaves as a variable of another type.
        If a class shares an IS-A or inheritance relationship with another class or interface, 
        their variables can be cast to each other's type. 
        Some times the cast is allowed and some times that cast is not allowed.

        */        
        float numb = (float)(5.25);
        int  intNumb = (int)(20.34);
        System.out.println("The number was Casted to " + " " + numb + " " + "This  is an  integer number " + " "  + intNumb);
    }
}
INFO