1. Can the switch statement be applied to byte, long, or string?
In switch (expr1), expr1 can only be oneInteger expressionOrEnumerated constants. Integer expressionIt can be the basic int type or integer packaging type. Because, byte, short, and char can be implicitly converted to int, these types and the packaging types of these types are also possible. Obviously, both the long and string types do not comply with the switch language regulations. And cannot be implicitly converted to int.
Type. Therefore, they cannot be applied to swtich statements.
2. Short S1 = 1; S1 = S1 + 1; what is the error? Short S1 = 1; S1 + = 1; what is the error?
For short S1 = 1; S1 = S1 + 1; because the S1 + 1 operation will automatically increase the expression type, the result is int type, and then assigned to short type S1, the compiler will report errors that require forced conversion.
For short S1 = 1; S1 + = 1; Because ++ = is an operator specified by the Java language, the Java compiler will perform special processing on it, so it can be compiled correctly.
3. Can a Chinese character be stored in a char variable? Why?
Char variables are used to store Unicode characters. The Unicode Character Set contains Chinese characters.Type variables can certainly store Chinese characters. However, if a special Chinese character is not included in the Unicode Character SetSo, this char variable cannot store this special Chinese character. Note: unicode encoding occupies two bytes,So, char
The Type Variable also occupies two bytes.
4. Can I call non-static methods from inside a static method?
NO. Because the non-static method must be associated with an object, you must create an object before you can call a method. You can call a static method directly without creating an object. That is, when a static method is called, no instance object is created, if you call a non-static method from a static method, which object is the non-static
method associated? This logic cannot be established. Therefore, a static method internally calls non-static methods.