References quiz

See here for more information about these pages and an index.

Question 1

Imagine we have the Room class from the previous page:

public class Room {
    public String text;
    
    public Room north;
    public Room south;
    public Room east;
    public Room west;
}    

Now we run the following Main class:

public class Main {
    public static void main(String[] args){

        Room a = new Room();
        a.text = "Fish room";

        Room b = a;

        b.text = "Telescope room";
        
        System.out.println(a.text+"/"+b.text);
    }
}

Question 2

With the same code, we now run the following Main class:

public class Main {
    public static void main(String[] args){

        Room a = new Room();
        a.text = "Fish room";
        Room b = new Room();
        b.text = "Telescope room";

        Room c = a;
        a = b;
        b = c;

        System.out.println(a.text+"/"+b.text);
    }
}
James Finnis
James Finnis
Lecturer in Computer Science

Research interests: artificial neuroendocrine systems, unusual neural network architectures, autonomous off-road driving, image processing.