Type Casting Flashcards
1
Q
What is type casting?
A
Type causing is when u assign a value of one primitive data type to another type.
2
Q
Are there types of type casting?
A
Yes, two. Widening casting and narrow casting.
3
Q
What is widening casting?
A
It’s converting a smaller type to a larger type size.
4
Q
What’s narrowing casting?
A
It is when you convert a larger type to a smaller size type.
5
Q
Example of widening casting?
A
It is done automatically.
Example.
public class Main 〔 public static void main(String[] args) 〔 int myInt = 9; double myDouble = myInt; // Automatic casting: int to double System.out.println(myInt); //prints 9 System.out.println(myDouble); //prints 9.0 〕 〕
6
Q
If you use narrow casting on a value 9.78, what does it become?
A
9