Lab Quiz Solution, Foundations of Computing, Spring, Week 2 -- Thurs Apr 12 2001

A single file contains the following Java code (exactly as it appears here, there is nothing else in the file). The is compiled by the Java compiler and the resulting Java program is run.


public class Alpha {

    static boolean p = false;



    public static void main(String args[]) {

	logic(p);          

	Beta.logic(p);     

	logic(Beta.p);     

	Beta.logic(Beta.p);

    }



    public static void logic(boolean p) {

	boolean q = false;

	System.out.println(" p " + p + "   q " + q

			   + "    p && q  " + (p && q) 

			   + "    p || q  " + (p || q));

    }

}



class Beta {

    static boolean p = true;



    public static void logic(boolean p) {

	boolean q = true;

	System.out.println(" p " + p + "   q " + q

			   + "    p && q  " + (p && q) 

			   + "    p || q  " + (p || q));

    }

}

  1. What is the name of this file?     Alpha.java

  2. What is the command to compile this file with the Java compiler?     javac Alpha.java

  3. What is the name of the file that the Java compiler produces?     Alpha.class (it also produces Beta.class)

  4. What does that file contain?     Java bytecodes

  5. What is the command to run the program?     java Alpha

  6. What output does the program produce? (Don't worry about getting the exact number of spaces or lining up the columns exactly -- just write the output reasonably neatly.)

    
     p false   q false    p && q  false    p || q  false
    
     p false   q true    p && q  false    p || q  true
    
     p true   q false    p && q  false    p || q  true
    
     p true   q true    p && q  true    p || q  true