Java Programming Language Quiz - 2
Test your knowledge of Java programming fundamentals including expressions, operators, type conversions, and String handling
Questions
Which one of the following syntactic constructs is not a simple expression?
- null
- 43
- x 2
- print()
Which one of the following escape sequences cannot appear in a string literal?
- \f
- \u
- "
- \\
Which one of the following is not a widening conversion rule?
- Short integer to character
- Integer to long integer
- Floating-point to double precision floating-point
- Character to floating-point
The ?: operator is an example of which kind of operator?
- Binary
- Prefix
- Postfix
- Infix
Which one of the following operators offers the fastest way to divide a negative integer by 2 and keep the negative result (e.g., -4/2 equals -2)?
- /
- %
- >>
- >>>
You read the following statement in a Java program that compiles and executes.
submarine.dive(depth);
What can you say for sure?
- depth must be an int
- dive must be a method.
- dive must be the name of an instance field.
- submarine must be the name of a class
- submarine must be a method.
Given the following class definition, which of the following methods could be legally placed after the comment //Here public class Rid{ public void amethod(int i, String s){} //Here }
- public void amethod(int s, String i){}
- public void Amethod(int i, String s) {}
- public void amethod(int i, String mystring){}
- None of the above
- public int amethod(int i, String s){}
Which of the following statements are true?
- Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type
- The size of a string can be retrieved using the length property.
- Strings are a primitive type in Java that overloads the + operator for concatenation
- The String class is implemented as a char array, elements are addressed using the stringname[] convention