Java Programming Language Quiz - 2

Test your knowledge of Java programming fundamentals including expressions, operators, type conversions, and String handling

8 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which one of the following syntactic constructs is not a simple expression?

  1. null
  2. 43
  3. x 2
  4. print()
Question 2 Multiple Choice (Single Answer)

Which one of the following escape sequences cannot appear in a string literal?

  1. \f
  2. \u
  3. "
  4. \\
Question 3 Multiple Choice (Single Answer)

Which one of the following is not a widening conversion rule?

  1. Short integer to character
  2. Integer to long integer
  3. Floating-point to double precision floating-point
  4. Character to floating-point
Question 4 Multiple Choice (Single Answer)

The ?: operator is an example of which kind of operator?

  1. Binary
  2. Prefix
  3. Postfix
  4. Infix
Question 5 Multiple Choice (Single Answer)

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)?

  1. /
  2. %
  3. >>
  4. >>>
Question 6 Multiple Choice (Single Answer)

You read the following statement in a Java program that compiles and executes.

submarine.dive(depth);

What can you say for sure?

  1. depth must be an int
  2. dive must be a method.
  3. dive must be the name of an instance field.
  4. submarine must be the name of a class
  5. submarine must be a method.
Question 7 Multiple Choice (Single Answer)

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 }

  1. public void amethod(int s, String i){}
  2. public void Amethod(int i, String s) {}
  3. public void amethod(int i, String mystring){}
  4. None of the above
  5. public int amethod(int i, String s){}
Question 8 Multiple Choice (Single Answer)

Which of the following statements are true?

  1. Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type
  2. The size of a string can be retrieved using the length property.
  3. Strings are a primitive type in Java that overloads the + operator for concatenation
  4. The String class is implemented as a char array, elements are addressed using the stringname[] convention