Java Type Casting

Java Type Casting in Hindi

Java

Java Type Casting in Hindi – Is Article Mai Ham Java Type Casting Ko Understand Karne Wale Hai Or Ye Dekh Wale Hai Ki Type Casting Kiya Hoti Hai |

Also Read – Java Data Types

Java Type Casting in Hindi

Type Casting Jab Ham Istemal karte Hai Jab Value 1 primitive data type se another data type mai convert kar Rahe Ho Ya Fir Value Assign Kar Rahe Ho|

Yadi Aapne  HTML Full Course  And CSS Full Course And Python Full Course And PHP Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Types Of Casting in Java In Hindi

Java Mai Type Casting 2 Types ki Hoti Hai. Inhe Ham Example ke Sath Understand karte Hai |

  • Widening Casting (automatically) 
  • Narrowing Casting (manually)

Upper Diye Gaye Type Casting Ko Ab Ham Ek Ek Karke Understand Karte Hai |

Widening Casting (automatically)

Widening Casting (automatically) Casting Ka Istemal Program Mai Automatically Hota Rahta Hai. Lekin Widening Casting Smaller Type Ko Larger Type Size Mai Convert karta Hai |

Example:

byte -> short -> char -> int -> long -> float -> double

public class MyClass {
  public static void main(String[] args) {
    int myInt = 9;
    double myDouble = myInt; // Automatic casting: int to double

    System.out.println(myInt);      // Outputs 9
    System.out.println(myDouble);   // Outputs 9.0
  }
}

Narrowing Casting (manually)

Narrowing Casting (manually) Casting Ka Istemal Program Mai manually Hota Hai. Lekin Narrowing Casting Larger Type Size Ko Smaller Type Size Mai Convert karta Hai |

Example:

double -> float -> long -> int -> char -> short -> byte

public class MyClass {
  public static void main(String[] args) {
    double myDouble = 9.78;
    int myInt = (int) myDouble; // Manual casting: double to int

    System.out.println(myDouble);   // Outputs 9.78
    System.out.println(myInt);      // Outputs 9
  }
}

Output:

9.78
9

Also Read – Java Variables And What is Java In Hindi

Friends Mujhe Umeed Hai Ki Aapko Type Casting in Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Leave a Reply

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