added datatypes precedence for good understanding (#26514)

* added datatypes precedence for good understanding

* Fixed formatting
This commit is contained in:
Maddineni Akhil
2019-01-08 20:57:38 +05:30
committed by Manish Giri
parent b519570336
commit 154ba84237

View File

@ -13,6 +13,8 @@ Java, type casting is classified into two types.
***1. Implicit Typecasting*** ***1. Implicit Typecasting***
Here, Automatic Type casting take place when the two types are compatible Here, Automatic Type casting take place when the two types are compatible
the target type is larger than the source type. the target type is larger than the source type.
Datatype precedence for implicit type casting (widening) is as follows :
`byte -> short -> int -> long -> float -> double`
eg. eg.
``` java ``` java
int i = 100; int i = 100;
@ -20,7 +22,8 @@ eg.
float f = l; //no explicit type casting required float f = l; //no explicit type casting required
``` ```
***2. Explicit Typecasting*** ***2. Explicit Typecasting***
When we assign a larger type value to a variable of smaller type, then we need to perform explicit type casting. When we assign a larger type value to a variable of smaller type, then we need to perform explicit type casting. Datatype precedence for Explict type casting (narrowing) is as follows :
`byte <- short <- int <- long <- float <-double`
eg. eg.
```java ```java
double d = 100.04; double d = 100.04;