From 154ba842378f080881a1b61b056eddeb1d770627 Mon Sep 17 00:00:00 2001 From: Maddineni Akhil Date: Tue, 8 Jan 2019 20:57:38 +0530 Subject: [PATCH] added datatypes precedence for good understanding (#26514) * added datatypes precedence for good understanding * Fixed formatting --- guide/english/java/typecasting/index.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guide/english/java/typecasting/index.md b/guide/english/java/typecasting/index.md index 8abc1fc5d2..3bedddff78 100644 --- a/guide/english/java/typecasting/index.md +++ b/guide/english/java/typecasting/index.md @@ -13,6 +13,8 @@ Java, type casting is classified into two types. ***1. Implicit Typecasting*** Here, Automatic Type casting take place when the two types are compatible 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. ``` java int i = 100; @@ -20,7 +22,8 @@ eg. float f = l; //no explicit type casting required ``` ***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. ```java double d = 100.04;