Quiz 2 (Attempt-2)
Quiz 2 (Attempt-2)
Quiz 2 (Attempt-2)
Instructions
You have 35 minutes to complete this quiz from the time that you begin.
You will have 2 attempts, with the best score being kept.
Attempt history
Attempt Time Score
KEPT Attempt 2 18 minutes 27.5 out of 30
Correct!
Each class must have one and only one constructor.
Question 2
1 / 1 pts
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 1/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
Correct!
z is available to code written outside the Circle class
Question 3
1 / 1 pts
The relationship between a class and an object is best described as
objects and classes are the same thing
Correct!
objects are instances of classes
Question 4
0 / 1 pts
class Test {
Test() {
g();
}
int g() {
System.out.println("Hi from g");
int h() {
System.out.println("Hi from h");
}
}
}
Correct answer
Compiling errors; no output
Hi from g
Hi from g Hi from h
Question 5
0.5 / 1 pts
Correct!
All variables must be given a type when they are declared.
The arithmetic operators *, /, \% and + all have the same level of precedence.
Correct!
The number of arguments in the method call must match the number of parameters in the method declaration.
You Answered
A local variable is declared in the body of a method and can be used anywhere within the class containing the method.
Question 6
1 / 1 pts
Which of these statements best describes a Java method?
It defines a blueprint from which objects are constructed
Correct!
It defines an action that an object can perform
Question 7
1 / 1 pts
Which of these statements about Java methods is not true?
The Java system provides standard (predefined) methods.
Correct!
Definition of a method may be included in the body of another method.
When a return statement executes in a user-defined method, the method immediately exits.
There are two types of user-defined methods: value-returning methods and void methods.
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 3/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
Question 8
1 / 1 pts
It is common practice in object-oriented programming to make all of a class' ...
Correct!
attributes private
attributes public
methods private
Question 9
1 / 1 pts
Which of these items is not something that you might find in a constructor?
A statement that assigns a newly created object to an instance variable.
Correct!
The definition of a new method.
Question 10
1 / 1 pts
A special method that is invoked to set up an object during instantiation is called a _________________
new method
creator
main method
Correct!
constructor
Question 11
1 / 1 pts
____________ are defined when a method is declared, while ____________ are defined when the
method is invoked
local variables; instance variables
Correct!
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 4/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
Question 12
1 / 1 pts
The behavior of an object is defined by the object's
instance data
constructor
Correct!
methods
visibility modifiers
Question 13
1 / 1 pts
Which of the following patterns should be used when instantiating a DecimalFormat object, if the
intended output format was 3.810?
Correct!
"0.000"
"0.0##"
"#.0"
"0.#"
"#.###"
Question 14
0 / 1 pts
Consider two methods, one private and the other public. Which statement does not apply to both
methods?
Both methods can have parameters and can return a value.
You Answered
Both methods can access private attributes of the class.
Correct answer
Both methods can be called by methods of other classes.
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 5/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
Question 15
1 / 1 pts
If you were examining the source code for a class, how would you distinguish methods from
constructors?
Correct!
Method names are user defined; constructors have the same name as the class.
Question 16
1 / 1 pts
Correct!
5, 8, 11, 14,
Question 17
1 / 1 pts
Correct!
it prints s out backwards
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 6/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
it prints s out backwards but does not print the 0th character
Question 18
1 / 1 pts
What would be the value of x after the following statements were executed?
int x = 10;
switch(x) {
case 10:
x += 15;
case 12:
x -= 5;
break;
default:
x *= 30;
}
25
Correct!
20
30
Question 19
1 / 1 pts
11
0
Correct!
12
10
Question 20
1 / 1 pts
int x = 10;
do {
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 7/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
System.out.println(x);
x--;
} while (x > 0);
9 times
0 times
Correct!
10 times
11 times
1 time
Question 21
1 / 1 pts
What should the loop control expressions be in order to make this code print the numbers counting
backwards from 20 to 10?
Correct!
int i = 20; i >= 10; i--;
Question 22
1 / 1 pts
What is the exact range of values you could use for number to terminate the following while loop?
Correct!
numbers in the range 100-500 (ends included)
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 8/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
Question 23
1 / 1 pts
The ____________ is ideal in situations where the exact number of iterations is known.
Correct!
for loop
if statement
while loop
do loop
Question 24
1 / 1 pts
What should the << loop control >> expression be in order to make this code count backwards from 100
by threes?
Question 25
1 / 1 pts
int x = 10;
for(int y = 5; y < 20; y += 5)
x += y;
Correct!
40
30
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 9/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
25
Question 26
1 / 1 pts
1 times 1 = 1
1 times 2 = 2
1 times 3 = 3
1 times 1 = 1
1 times 2 = 2
1 times 3 = 3
Correct!
infinite loop
1 times 1 = 1
1 times 2 = 2
1 times 3 = 3
1 times 1 = 1
1 times 2 = 2
1 times 3 = 3
1 times 1 = 1
2 times 1 = 2
3 times 1 = 3
Question 27
1 / 1 pts
Choose the best word to fill in the blank in the statement: "The do ... while statement tests the loop-
continuation condition ___________ executing the loop's body ".
before
when
Correct!
after
always
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 10/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
Question 28
1 / 1 pts
int x = 11;
do {
x += 20;
} while (x > 100);
Correct!
1
Question 29
1 / 1 pts
int x = 1;
for (int y = 1; y <= 10; y++) {
if (y > 7) x++;
}
System.out.println(x);
2
Correct!
4
Question 30
1 / 1 pts
int x = 0;
for (int y = 1; y <= 10; y++) {
if (y % 2 != 0)
x++;
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 11/12
4/24/24, 11:17 PM Quiz 2 - Modules 5 and 6: Computer Programming 1 GE | COMP8702 ONC-U + ONC-FP S1 2024
}
System.out.println(x);
Correct!
5
10
https://canvas.flinders.edu.au/courses/18866/quizzes/122359 12/12