-1

I tried

'''
Object b = 3;
char cdd = (Character) b;
System.out.print(cdd);
'''

but it has the following error. Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Character How can I fix it?

able20
  • 167
  • 1
  • 1
  • 7

1 Answers1

1

First cast to int and after that to char

Object b = 98;
int cdd = (int) b;
System.out.println(cdd);
System.out.println((char) cdd);

Output is

98
b
Butiri Dan
  • 1,759
  • 5
  • 12
  • 18