Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

HONG KONG INTERNATIONAL

COMPUTATIONAL OLYMPIAD
HEAT ROUND 2019 - 2020 (HONG KONG REGION)

Java
Time allowed: 60 minutes
Question Paper
Instructions to Contestants:
1. Each contestant should have ONE Question-Answer Book which CANNOT be taken away.
2. There are a total of 20 questions in this Question-Answer Book. Two points for correct answers. No points
for incorrect answers. ONE penalty point will be deducted for incorrect answers.
3. All answers should be written on ANSWER SHEET.
4. During the contest, NO calculators can be used for PRIMARY GROUP but calculators can be used for
SECONDARY GROUP.
5. All figures in the paper are not necessarily drawn to scale.
6. This Question-Answer Book will be collected at the end of the contest.

THIS Question-Answer Book CANNOT BE TAKEN AWAY.


DO NOT turn over this Question-Answer Book without approval of the examiner.
Otherwise, contestant may be DISQUALIFIED.
Multiple Choice Questions (1st ~20th) (Two points for correct answers. No points for incorrect answers. ONE
penalty point will be deducted for incorrect answers.)

1. Java source code is compiled to byte code, which is then executed by the JVM. What is Java?

A. Compiled language
B. Interpreted language
C. Markup Language
D. Machine language
E. None of the above

2. What is Java used in?


A. Server computer
B. Mobile devices
C. Home appliances
D. All of the above
E. None of the above

3. Which of the following classes is not used for I/O in Java?

A. java.util.Scanner
B. java.io.PrintStream
C. java.io.Console
D. None of the above
E. All of the above

4. Which of the following is a correct import statement?

A.
B.
C.
D.
E. None of the above
Consider the following code for question 5 to 7:

5. Argument list „args[]‟ of method MyClass.main is supplied with values given at?

A. Compile time
B. Runtime
C. First at compile time but can be overridden at runtime
D. Runtime but would be overridden if already defined at compile time
E. None of the above

6. In what condition the identifier public of class MyClass is necessary for the source code file MyClass.java
to compile?

A. Any condition, public identifier is optional


B. public is not a valid identifier for class thus the above code cannot compile
C. When the class MyClass is expected to be accessed outside local package
D. When public is also presented in definition of main
E. None of the above

7. What is the expected output (in console) when the compiled code is executed with the command
`java MyClass a=20 b=30`?

A. 50
B. 35
C. Sum of a and b = 35
D. Sum of a and b = 2030
E. None of the above
8. What is the expected output of the following code?

A. 25
B. 50
C. 75
D. Compile Error
E. None of the above

9. What is the expected output of the following code? (You can refer to the ASCII table provided in
APPENDIX)

A. 65
B. A
C. Compile Error
D. Runtime Error
E. None of the above

10. Which of the following is an incorrect method definition?

A.
B.
C.
D. All of the Above
E. None of the above
11. Which of the provided option(s) could be filled in the following code (indicated with comment) so that the
code could compile without error?

A.

B.
C.
D. All of the above
E. None of the above

12. What is the expected output when the following code is executed with terminal command java Main a=2
c=3?

2
3
A.
2

3
B.
a=2
a=3
C.
a=2

a=3
D.
E. None of the above
Refer to the following code for question 13 and 14:

13. What is the expected output of the code executed with the terminal command java Main 2 3?

A. 5
B. 23
C. 255
D. 333
E. None of the above

14. Would the program compile without error if the command is changed to java Main a=2 b=3 c=4?

A. Yes, program compile without error


B. No, compile error at line 4
C. No, compile error at line 9
D. No, compile error at line 25
E. None of the above
Refer to the following code for question 15 and 16:

15. A student writes a program calculating Fibonacci sequence but the program failed to compile. Which of the
following is/are valid explanation(s)?

A. Recursion is used without terminating case


B. He / She didn‟t consider the cases where n < 1
C. fib is not a static method
D. All of the above
E. None of the above

16. After fixing the code, the student wants to print the whole sequence till the n-th term instead of n-th term
only. He / She wants to keep using recursion, his / her friend tells him/she that recurson is impossible, for-
loop should be used instead. Which of the following is a correct statement?

A. The friend is correct, recursion is not plausible when output of intermediate terms is necessary.
B. The friend is not correct, only recursion is plausible in this case.
C. The friend is not correct, for-loop and recursion are both applicable.
D. For-loop and recursion should never be used in any case, because of their low complexity.
E. None of the above

17. Assume java.math.BigInteger is imported, expression


evaluates to? If false, why?

A. true
B. false, because integer 5 does not equal to a string “5”
C. false, because object reference should not be compared directly with „==‟
D. Compile error because string “5” is not an integer
E. None of the above
18. Given the following code:

Values of booleans a and b in Main.main respectively are?

A. true and true


B. false and false
C. true and false
D. false and true
E. The code would result in compile error
19. Can the following code compile without error? If not, what is the explanation?

A. Yes, the code can compile without error


B. No, constructor Bar accesses member this.a is undefined in parent Foo
C. No, constructor Bar does not invoke super()
D. No, Main.main contains invalid code
E. None of the above

20. What is the expected output of the following code?


A.
B.
C.
D.
E. Compile Error

~ 全卷完 ~
~ End of Paper ~
APPENDIX I: ASCII TABLE

You might also like