Multiple choice java

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

In the statement submarine.dive(depth), the dot operator (.) is used to access a member of the object referenced by 'submarine'. Since parentheses follow 'dive', it is a method call. 'depth' is an argument (could be int, double, etc., not necessarily int), and 'submarine' is a reference variable, not the class name itself.