1
2
3
100

public class Dog { // implementation not shown}
public class Cat { // implementation not shown}
public class Main {
    public static void main(String[] args) {
        Dog dog = new Dog(); dog.name = “doggy”;
        Cat cat = new Cat(); cat.name = “catty”;
        System.out.println(dog.name);
        System.out.println(cat.name); } }
Assuming that Dog and Cat have accessible and functional initialisers, what will be the output of this code?

doggy

catty

100

public class Example {

    public static void main(String[] args) {

        int x = 5;

        if (x > 3) {

            x = x + 2;

        } else {

            x = x - 2; } } }

What is value of x after the code segment executes?

7

100

How many stars are output when the following code is executed?

for (int i = 0; i < 5; i++) {

    for (int j = 0; j < 5; j++)

        System.out.println("*");

}

25

200

What does this boolean expression evaluate to?

(!(!a || !b) && !(!(a && b!))) || !(!(a && !b))

a
200

In which of the following codes does c correctly evaluate to the hypotenuse of a right triangle?

a) double a; double b; double c = Math.sqrt(a*a + b*b);

b) int a; int b; double c = a*a + b*b; c = Math.sqrt(c, 2);

c) int a; double b; int c = Math.sqrt(a*a + b*b, 2);

a

200

Consider the following code: (int)(Math.random() * (y - x)) + y. 

What is the upper and lower bounds of this random function?

Lower: y

Upper: 2y - x

300

boolean x = true;

boolean y = false;

boolean z = true; 

if ((!x || y) && (x || !y || z)) {

System.out.print(x && (!y || !z));
}

What is output?

Nothing

300

public class Book() {

  private int pages;

  private String title;

  private int lexile;

  public Book() {

    pages = 420;

    title = “Romeo and Juliet”;

    lexile = 1000; } }

If someone creates a new book object called book1 in a Main class, what is outputted when they print book1.lexile?

Nothing

300

What three escape sequences have we learned in class and what do they do?

\" = prints quote symbol

\\ = prints backslash symbol

\n = prints newline character

M
e
n
u