🎴 Flashcard Mode
Basics of Java Programming
Card1 / 14
Mastered0
Review0
QuestionClick to flip
What is the output of following Java program?
public class Test
{
public static void main(String[] args)
{
double i=45.6567;
float j=i;
System.out.println( j );
}
}
AnswerClick to flip back
A
Run time Exception
💡 Explanation:
As variable 'i' is of double and 'j' is of float , we cannot assign a data type with lower precedence with data type of higher precedence. Explicit type cast must be done in order to assign a data type with lower precedence with a data type of higher precedence.
i.e float j=(float)i; which type casts the double datatype to float data type
As the explicit type casting is not done in the given program, hence we get run time exception.