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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Are there types of type casting?

A

Yes, two. Widening casting and narrow casting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is widening casting?

A

It’s converting a smaller type to a larger type size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s narrowing casting?

A

It is when you convert a larger type to a smaller size type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
       〕    〕
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If you use narrow casting on a value 9.78, what does it become?

A

9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly