1) norowning (long->byte)
1) arrowing in Java, also known as explicit type casting or downcasting, involves converting a value from a larger data type to a smaller one.
2)This process requires explicit syntax because it can potentially lead to data loss or precision reduction.
Why is it needed in arrowing?
Memory Management:
- When dealing with , using smaller data types can optimize memory usage.
Specific Operations:
- some operations might require specific data types, necessitating a conversion even if it's a narrowing one.
Data Loss:
- Narrowing can result in loss of precision (e.g., decimal part truncation) or unexpected values due to overflow. *Careful Usage: Use narrowing conversions with caution, ensuring that the potential loss of data is acceptable for your specific use case. ex: double d = 123.45; int i = (int) d; // i will be 123 (decimal part is truncated)
- some operations might require specific data types, necessitating a conversion even if it's a narrowing one.
Data Loss:
broadning (int->long)
also known as implicit conversion or upcasting, in Java refers to the automatic conversion of a smaller data type to longer date type
Ex
int myInt = 10;
long myLong = myInt; // Implicit conversion from int to long
double myDouble = myInt; // Implicit conversion from int to double
Access modifiers
access modifiers are essential tools that define how the members of a class, like variables, methods, and even the class itself can be accessed from other parts of our program.
Types of Access Modifiers
There are 4 types of access modifiers available in Java:
Default
Private
Protected
Public
Default
*declarations are visible only within the package (package private)
Private
* declarations are visible within the class only
Protected
*declarations are visible within the package or all subclasses
Public
* declarations are visible everywhere
Refffer tha webset
https://www.geeksforgeeks.org/strings-in-java/
Top comments (0)