Type Casting in Java

Changing over one information type to another information type is known as

type throwing. Type Casting in Java is of two sorts, for example, Certain TypeCasting which

is otherwise called Automatic Type Casting and Explicit Type Casting.

Certain or Automatic Type Casting

  • In this, littler information type is changed over to greater information type which
  • is otherwise called extending.
  • There is no information misfortune possibility.
  • It is finished by the compiler in this way it is known as programmed
  • type throwing.
  • Model: byte b=10; int x=b; Here byte type is changed over to
  • int type.

Unequivocal Type Casting

  • In this, greater information type is changed over to littler information type which is otherwise called narrowing.
  • There is information misfortune possibility.
  • It is finished by the client with the assistance of typecast administrator for example Model: int x=10; byte b=(byte)x; Here int type is
  • changed over to byte type.

Type Promotion in Java

  • Changing over littler information type to greater information type is known as type advancement.
  • Just advancement is permitted, the downgrade isn’t permitted.

Type Promotion Chart

  • This graph educates us regarding the progression of changing over one littler
  • information type to another greater information type.
  • Twofold can’t be changed over to any information type.
Type Casting in Java
Note: Long takes 8 bytes while coast takes 4 bytes, rather than that long (greater sort) can be
changed over to coast (littler sort) which is a special case.

Leave a Comment

error: Alert: Content is protected!!