Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Does "casting" allow a variable to be used in more than one method at the same time?

+5 votes
asked Oct 10, 2017 in CSC 211 (F17) by Yafet Zeleke (100 points)

2 Answers

0 votes
no casting allows you to turn one primitive type into another
answered Oct 11, 2017 by Emilio Moscosa (100 points)
0 votes
No casting is performing to find super class for the class that you are trying to cast. For example you can cast a double into an integer since an integer is a double. But no you need to save it to another variable since the old one probably is declared with different type.

Example :

double myDouble = 2.0;

int myInt = (int) (myDouble);

that is going to give you an integer version of myDouble but myDouble is still unaltered.
answered Oct 11, 2017 by Dat Tran (100 points)