Added a section called "Casting". Details on how data types can be stored in other data types. (#23881)
* Added a section called "Casting" * Reordered section, fixed typo
This commit is contained in:
committed by
Manish Giri
parent
7f00161e60
commit
61b6f1e19e
@ -197,3 +197,19 @@ Output:
|
||||
```
|
||||
10198442
|
||||
```
|
||||
|
||||
### Casting
|
||||
|
||||
It is also important to note that it is possible to store different data types into one another. However, you would have to let the compiler know that you have acknowledge the possible loss of data by casting the variable.
|
||||
|
||||
For example:
|
||||
```java
|
||||
double d = 1.23
|
||||
|
||||
int i = (int)d;
|
||||
System.out.println(i);
|
||||
```
|
||||
Output:
|
||||
```
|
||||
1
|
||||
```
|
||||
|
Reference in New Issue
Block a user