Implicit Type Conversion Example in Java

Write a program to perform implicit type conversion

Program or Solution

				
				
					

class Program

{

public static void main(String args[])

{

byte b = 10;

char ch = 'C';

short num = 500;

int i;

i = b;

System.out.println(i);

i = ch;

System.out.println(i);

i = num;

System.out.println(i);

num = b;

System.out.println(num);

//Following Conversions are not possible implictly because size of i is 4 bytes, ch is 2 bytes, b is 1 byte and num is 2 bytes 

//b=i; // size of i is greater than b

//ch =i; // size of i is greater than ch

//b = num; // size of num is greater than b

//num = i; // size of i is greater than num

}

}


Output

Implicit Type Conversion Example in Java Output

Program Explanation

Implicit Type casting take place when, the two types are compatible, the target type is larger than the source type.

The Commented lines are not possible because source types are larger than destination types.

Comments

ubaTaeCJ
-1 OR 2+515-515-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3+515-515-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3*2<(0+5+515-515) --
ubaTaeCJ
-1 OR 3*2>(0+5+515-515) --
ubaTaeCJ
-1 OR 2+212-212-1=0+0+0+1
ubaTaeCJ
-1 OR 3+212-212-1=0+0+0+1
ubaTaeCJ
-1 OR 3*2<(0+5+212-212)
ubaTaeCJ
-1 OR 3*2>(0+5+212-212)
ubaTaeCJ
-1' OR 2+470-470-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3+470-470-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3*2<(0+5+470-470) --
ubaTaeCJ
-1' OR 3*2>(0+5+470-470) --
ubaTaeCJ
-1' OR 2+537-537-1=0+0+0+1 or 'Oi9smyom'='
ubaTaeCJ
-1' OR 3+537-537-1=0+0+0+1 or 'Oi9smyom'='
ubaTaeCJ
-1' OR 3*2<(0+5+537-537) or 'Oi9smyom'='
ubaTaeCJ
-1' OR 3*2>(0+5+537-537) or 'Oi9smyom'='
ubaTaeCJ
-1" OR 2+855-855-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3+855-855-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3*2<(0+5+855-855) --
ubaTaeCJ
-1" OR 3*2>(0+5+855-855) --
ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
ubaTaeCJ
-1; waitfor delay '0:0:15' --
ubaTaeCJ
-1); waitfor delay '0:0:15' --
ubaTaeCJ
1 waitfor delay '0:0:15' --
ubaTaeCJ
mmQwJAgI'; waitfor delay '0:0:15' --
ubaTaeCJ
-5 OR 892=(SELECT 892 FROM PG_SLEEP(15))--
ubaTaeCJ
-5) OR 267=(SELECT 267 FROM PG_SLEEP(15))--
ubaTaeCJ
-1)) OR 835=(SELECT 835 FROM PG_SLEEP(15))--
ubaTaeCJ
BKF5VlTC' OR 957=(SELECT 957 FROM PG_SLEEP(15))--
ubaTaeCJ
Iwdv2ZfM') OR 170=(SELECT 170 FROM PG_SLEEP(15))--
ubaTaeCJ
0pPK1MaM')) OR 950=(SELECT 950 FROM PG_SLEEP(15))--
ubaTaeCJ
*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
ubaTaeCJ
'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
ubaTaeCJ
1'"
ubaTaeCJ
@@LlyJb