Examveda
Examveda

Automatic type conversion in Java takes place when

A. Two type are compatible and size of destination type is shorter than source type.

B. Two type are compatible and size of destination type is equal of source type.

C. Two type are compatible and size of destination type is larger than source type.

D. All of the above

Answer: Option A

Solution(By Examveda Team)

In Java, automatic type conversion, also known as widening or implicit type conversion, occurs when assigning a value of one data type to another data type. This conversion takes place under certain conditions:

When two types are compatible and the size of the destination type is shorter than the source type, automatic type conversion occurs. This is because there is no risk of data loss when moving from a larger data type to a smaller one.

If the size of the destination type is equal to or larger than the source type, automatic type conversion is not necessary, as there is no risk of data loss in these cases.

Therefore, the correct option is Option A.

This Question Belongs to Java Program >> Data Types And Variables

Join The Discussion

Comments ( 7 )

  1. Madagalam UmaMaheswari
    Madagalam UmaMaheswari :
    3 weeks ago

    Ok let me explain the concept behind this is implicit type casting .
    where java/jvm easily convert RHS TO LHS side type when the range/memory is huge on LHS and RHS is small range/memory then LHS ,so when we assign like this example :- long a = 32667777888;(remember in java long automatically treats as int unless and until you add L in the suffix to literal(to value);so on RHS side it is practically we are willing to store an int literal(value)---(this is source type) and assigning it to long on LHS where two or different types but compatible(same type of data that is decimal value ) as LHS has long storage capacity is huge---(destination type) so it can store int value easily without any complation error.but when we try to assign RHS Value more than int range it gives you compilation error -- (size is exceed like that ) then the scenario of adding "L" at suffix to RHS value comes into picture beacuse java treats long value as int within its range.so to end it the destination type is LHS and source type is RHS ,RHS is always have huge storage capacity then LHS (then only java will auttomatically convert type implictly)and that should be compatible means have same work in same type data (decimal values).same goes with float and double and char.

  2. Mujammil Ali
    Mujammil Ali :
    6 years ago

    solution me

  3. Nikhil Rj
    Nikhil Rj :
    6 years ago

    Sorry 2nd example was wrong
    float f=123l;
    compiled successfully and executed successfully... Where as size of long is larger than float..

  4. Nikhil Rj
    Nikhil Rj :
    6 years ago

    I need to give you another example..
    long l=1.7f;
    Compiled successfully and execute successfully..
    Size of long is larger than float...

  5. Nikhil Rj
    Nikhil Rj :
    6 years ago

    Wrong question
    char c=10;
    Compiled successfully and run successfully where as 10 is by default int type.
    10 is here auto casted to char..

  6. Harshad Khot
    Harshad Khot :
    7 years ago

    byte have 8 bits i'e 1 byte and short have 2 byte. if you convert value byte to short then it convert it automatically bcz byte is lesser then short but convert short to byte then it no converting bcz short is greeter then byte .

  7. Karthik Raja
    Karthik Raja :
    7 years ago

    plz explain this question......

Related Questions on Data Types and Variables