Expliciete typecast |
Een voorbeeld van een noodzakelijke expliciete typecast
quotientInt= 3.0 quotientDouble= 3.2 |
import java.io.*;
class TypecastExApp {
static public void main(String args[] ) throws IOException {
double quotientInt, quotientDouble, rest;
int x = 16, y = 5;
// Stap1 zonder expliciete typecast quotientInt = x / y; // quotientInt = 3 // Stap2 met expliciete typecast quotientDouble= (double)x / y; // quotientDouble = 3.2 System.out.println( "quotientInt= " + quotientInt); System.out.println( "quotientDouble= " + quotientDouble); } } |
In dit voorbeeld moet er in de deling een expliciete typecast uitgevoerd worden,
Stap1 zonder expliciete typecast
Stap2 met expliciete typecast