Computer Science Quiz
Question 1
Question text
A subclass will _____ one superclass.
Select one:
a. extend
b. implement
c. inherit
d. overload
e. override
Clear my choice
Question 2
Question text
Consider the following Java method.
public static void main(String[] args) {
System.out.println(“Hello, Final!”);
}
Which term best describes ‘”Hello, Final!”‘?
Select one:
a. actual parameter or argument
b. formal parameter
c. modifier
d. return type
e. superclass
Clear my choice
Question 3
Question text
A subclass method can _____ a superclass method with the same name and parameter types.
Select one:
a. extend
b. implement
c. inherit
d. overload
e. override
Clear my choice
Question 4
Question text
Which of the following is NOT a valid identifier in Java?
Select one:
a. p
b. Public
c. public
d. public1
e. PuBlIc_oNe
Clear my choice
Question 5
Question text
What is the output of the following Java program?
public class Food {
static int count;
private String flavor = “sweet”;
Food(String s) { flavor = s; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food(“spicy”);
Food chile = pepper;
pepper.setFlavor(“smoky”);
System.out.println(chile.getFlavor());
}
}
Select one:
a. false
b. smoky
c. spicy
d. sweet
e. true
Clear my choice
Question 6
Question text
What is the output of the following Java program?
interface Food {
public void printFlavor();
}
class Pepper implements Food {
public void printFlavor() { System.out.println(“spicy”); }
}
public class Lunch {
public static void main(String[] args) {
Food pepper = new Pepper();
pepper.printFlavor();
}
}
Select one:
a. bland
b. bland
spicy
c. (no output)
d. spicy
e. the program does not compile
bland
Question 7
Question text
An object that registers listener objects does which of the following?
Select one:
a. It generates events.
b. It handles events.
c. It records audio.
d. It runs an event loop.
e. It maintains an object directory.
Clear my choice
Question 8
Question text
Consider the following class definition. Which variables can be used in the missing “println” expression on line 20?
1 public class PrintStuff
2 {
3 public static void main()
4 {
6 {
7 int i = -1;
8 System.out.println(_____);
9 }
10 int j = 1;
11 for (j = 0; j < 10; j++) {
12 System.out.println(_____);
13 }
14 {
15 int k;
16 for (k = 0; k < 10; k++) {
17 System.out.println(_____);
18 }
19 }
20 System.out.println(_____);
21 }
22 }
Select one:
a. “i” and “j”.
b. “j” and “k”
c. Only “i”
d. Only “j”
e. Only “k”
Question 9
Question text
Consider the following Java program. Which one of the following best describes “pepper”?
public class Food {
static int count;
private String flavor = “sweet”;
Food() { count++; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food();
System.out.println(pepper.getFlavor());
}
}
Select one:
a. a constructor
b. a local object variable
c. an instance variable
d. a method
e. a class variable
Clear my choice
Question 10
Question text
What is the output of the following Java program?
abstract class Food {
abstract void printFlavor();
}
class Pepper extends Food {
void printFlavor() { System.out.println(“spicy”); }
}
public class Lunch {
public static void main(String[] args) {
Food pepper = new Food();
pepper.printFlavor();
}
}
Select one:
a. bland
b. bland
spicy
c. (no output)
d. spicy
e. the program does not compile
bland
Question 11
Question text
A subclass will _____ from its superclasses.
Select one:
a. extend
b. implement
c. inherit
d. overload
e. override
Clear my choice
Question 12
Question text
Consider the following Java method.
public static void main(String[] args) {
System.out.println(“Hello, Final!”);
}
Which term best describes “void”?
Select one:
a. actual parameter or argument
b. formal parameter
c. modifier
d. return type
e. superclass
Clear my choice
Question 13
Question text
Consider the following Java program. What is the superclass of “Clicker”?
import java.awt.event.*;
import javax.swing.*;
public class Clicker extends JFrame implements ActionListener {
int count;
JButton button;
Clicker() {
super(“Click Me”);
button = new JButton(String.valueOf(count));
add(button);
button.addActionListener(this);
setSize(200,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
count++;
button.setText(String.valueOf(count));
}
public static void main(String[] args) { new Clicker(); }
}
Select one:
a. ActionEvent
b. ActionListener
c. JButton
d. JFrame
e. String
Clear my choice
Question 14
Question text
What is the output of the following Java program?
import java.util.*;
class ArrayGames {
public static void main(String[] args) {
int[] a = {1,2,3,4,5};
for (int i = 0; i < a.length; i++) a[i] += a[i];
System.out.println(Arrays.toString(a));
}
}
Select one:
a. [0, 1, 2, 3, 4]
b. [1, 1, 1, 1, 1]
c. [1, 2, 3, 4, 5]
d. [2, 4, 6, 8, 10]
e. [1, 4, 9, 16, 25]
Question 15
Question text
Which of the following types is NOT a primitive type?
Select one:
a. boolean
b. char
c. double
d. int
e. String
Clear my choice
Question 16
Question text
What is the output of the following Java program?
public class Food {
static int count;
private String flavor = “sweet”;
Food(String s) { flavor = s; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food(“spicy”);
Food chile = new Food(“spicy”);
System.out.println(pepper == chile);
}
}
Select one:
a. false
b. smoky
c. spicy
d. sweet
e. true
Clear my choice
Question 17
Question text
In a for loop, how many times does the update run?
Select one:
a. Zero or more times, at the beginning of each iteration.
b. Zero or more times, at the end of each iteration.
c. At least once, at the beginning of each iteration.
d. At least once, at the end of each iteration.
e. Exactly once.
Clear my choice
Question 18
Question text
Each of the individual tasks that a CPU is working on is called:
Select one:
a. a component
b. an address
c. a message
d. an object
e. a thread
Clear my choice
Question 19
Question text
Question Text: Consider the following line of Java code. ‘”Hello,World'” is which of the following?
System.out.println(“Hello, World!”);
Select one:
a. a class
b. a method
c. an object
d. an operator
e. a parameter
Clear my choice
Question 20
Question text
What is the output of the following Java program?
import java.util.*;
class ArrayGames {
public static void main(String[] args) {
int[] a = {1,2,3,4,5};
System.out.println(a[1]);
}
}
Select one:
a. 1
b. 2
c. 3
d. 4
e. 5
