Oracle Certified Professional Java Se 11 Developer · Free Practice Question Easy
Question 45
Question ID: UKOCP61265
Following statement in a Java program compiles successfully:
student.report(course);
What can you say for sure?
- A student is the reference variable name
- B student is the class name
- C report is the method name
- D course must be of String type
Reveal correct answer
Correct answer: C
Explanation
UKOCP61265:
It is good practice to have first character of class name in upper case, but it is not mandatory.
student can be either class name or reference variable name.
Syntax to invoke static method is: Class_Name.method_name(<arguments>); OR reference_variable_name.method_name(<arguments>);
Syntax to invoke instance method is: reference_variable_name.method_name(<arguments>);
If student represents class_name or refernce_variable_name, then report might be the static method of the class.
If student represents reference_variable_name, then report is the instance method of the class.
In both the cases, report must be the method name.
Type of argument cannot be found out by looking at above syntax.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
