I'm trying to get the minimum and maximum values of the byte data type printed but the Byte.MIN_VALUE
& the Byte.MAX_VALUE
are highlighted in red in the IDE. I'm using IntelliJ IDEA community edition. Would someone be able to help, please? Thanks in advance.
public class Byte {
public static void main(String[] args){
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MIN_VALUE;
System.out.println("Byte Minimum Value = " + myMinByteValue);
System.out.println("Byte Maximum Value = " + myMaxByteValue);
}
}
You are giving Class Name as Byte so its refer the same class name. Change the class name to some other name.
public class Test {
public static void main(String[] args){
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MIN_VALUE;
System.out.println("Byte Minimum Value = " + myMinByteValue);
System.out.println("Byte Maximum Value = " + myMaxByteValue);
}
}
You have declared your own Byte
class. (Bad idea...)
Within your Byte
class, references to Byte
are referring to >>this<< class, not to java.lang.Byte
. But your Byte
class does not declare MIN_VALUE
or MAX_VALUE
. Hence the compilation error... indicated by the red highlighting.
Solutions:
Change the name of your class. It is a bad idea to use a name for your class that is the same as the name of a standard class. If leads to various confusing compilation errors....
Use the qualified name for the standard class; ie change
byte myMinByteValue = Byte.MIN_VALUE;
to
byte myMinByteValue = java.lang.Byte.MIN_VALUE;
"Byte" is a reverse word or keyword of java. You can't use any reserve word(keyword) as a class name or variable name. Change your class name.
class Test{
public static void main(String[] args){
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MIN_VALUE;
System.out.println("Byte Minimum Value = " + myMinByteValue);
System.out.println("Byte Maximum Value = " + myMaxByteValue);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.