Can We store a double value in a long type variable without casting?

By | August 22, 2019

In this post we will discuss about one of the basic  java interview question and question is that Can We store a double value in a long type variable without casting?

We cannot store a double value into a long type variable without casting because the range of double is greater than long and that’s why we need to type cast. It’s not difficult to answer this question but many developers get it wrong due to confusion on which one is bigger between double and long in Java.

Let’s understand above concept using an example

Sample Output

200

You may also like:

Encapsulation in Java
Abstraction in Java
Understating of Polymorphism in Java
Method Overloading or Static Polymorphism in Java
Method Overriding or Dynamic Polymorphism in Java
Understating of Inheritance in Java
Difference Between Encapsulation and Abstraction in Java
Association Aggregation And Composition in Java

That’s all about Can We store a double value in a long type variable without casting?
If you have any feedback or suggestion please feel free to drop in blow comment box. 

Leave a Reply

Your email address will not be published. Required fields are marked *