Lab Quiz, Foundations of Computing, Spring, Week 4 -- Thurs Apr 26 2001

Name:


Two files contain the following Java code (exactly as it appears here, there is nothing else in the files). The files are compiled by the Java compiler and the resulting Java program is run.

// Ticket.java
public class Ticket {
    static int n = 0;

    public static void total() { 
	System.out.println(n + " tickets have been issued");
    }

    int ticket;

    public Ticket() {
	ticket = n;
	n++;
    }

    public void speak() {
	System.out.println("I have ticket " + ticket);
    }
}

// TicketDemo.java
public class TicketDemo {
    public static void main(String[] args) {
	Ticket a, b, c;
	Ticket.total();
	a = new Ticket(); a.speak(); Ticket.total();
	b = new Ticket(); b.speak(); Ticket.total();
	c = new Ticket(); c.speak(); Ticket.total();
    }
}
  1. What is (are) the class variable(s) in the Ticket class?

  2. What is (are) the instance variable(s) in the Ticket class?

  3. What is (are) the class method(s) in the Ticket class?

  4. What is (are) the instance method(s) in the Ticket class?

  5. What output does the program produce?