Asha K

Greenhorn
+ Follow
since Feb 17, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Asha K

I saw this question in a mock test. I am not able to understand how the answer is D
1: int i = 1;
2: i <<= 31;<br /> 3: i >>= 31;
4: i >>= 1;
5:
6: int j = 1;
7: j <<= 31;<br /> 8: j >>= 31;
9:
10: System.out.println("i = " +i );
11: System.out.println("j = " +j);
A) i = 1
j = 1
B) i = -1
j = 1

C) i = 1
j = -1

D) i = -1
j = -1

Answer
24 years ago
public class T {
public static void main(String [] args) {
int myInt = 1;
char myChar = 'c';
myInt = myChar; //works
myChar=98; //works
myChar = myInt;//Does not work. Why?
}
}
T.java:7: Incompatible type for =. Explicit cast needed to convert int to char.
myChar = myInt;
^
24 years ago