public class Main{
public static void main(String[] argv){
char ch = 'a';
int num = 99;
ch = num ;
}
}
Compiling the code above will generate the following error message.
public class Main {
public static void main(String[] argv) {
char ch = 'a';
int num = 99;
ch = num;
}
}
Compiling the code above will generate the following error message.
D:\>javac Main.java
Main.java:5: possible loss of precision
found : int
required: char
ch = num;
^
1 error
Java performs an automatic type conversion
when storing a literal integer constant into variables of type byte, short, or long.
public class Main {
public static void main(String[] argv) {
byte b = 1;
}
}
But you cannot store a value out of the byte scope
public class Main{
public static void main(String[] argv){
byte b = 11111;
}
}
When compiling, it generates the following error message:
D:\>javac Main.java
Main.java:3: possible loss of precision
found : int
required: byte
byte b = 11111;
^
1 errorjava2s.com | | Contact Us | Privacy Policy |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |