Multiple choice technology programming languages

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.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The statement submarine.dive(depth) uses dot notation, which in Java can represent: 1) A method call: object.method() 2) Field access: object.field 3) Nested class access: Outer.Inner 4) Enum constant access. In this context, 'dive' followed by parentheses with an argument 'depth' indicates a method invocation. This is the only certainty - dive is definitely a method. We cannot be certain about 'depth' (it could be int, long, Integer, etc., depending on the method signature), nor about 'submarine' (it could be a variable of any type, not necessarily a class name).