English

Explain the following: Type Conversion and its forms

Advertisements

Question

Explain the following:

Type Conversion and its forms

Explain
Advertisements

Solution

Type Conversion in Java is the process of converting a value from one data type into another data type. It is used when a value of one data type needs to be assigned to a variable of another data type.

1. Implicit Type Conversion (Automatic Conversion):

Implicit type conversion is the process in which Java automatically converts a smaller compatible data type into a larger data type without any loss of information.

Example:

int a = 10;
double b = a;

2. Explicit Type Conversion (Type Casting):

Explicit type conversion is the process in which the programmer manually converts a value from one data type into another using the casting operator. It may result in loss of data.

Example:

double a = 10.75;
int b = (int) a;
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 34. (b) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×