CS670K Homework Set 4 - Fall 1998

Due: Thursday, November 5

© Copyright University of New Haven 1998

What is printed in the following programs?

  1. 	class X
    	{
    	     int  a[][]= { {1, 2}, {3, 4} };
    	     int  i;
    	     Integer n= new Integer(6);
    	     Integer t[]= new Integer[3];
    
    	     X()
    	     {
    	          for  (i= 0;  i < 3;  ++i)  t[i]= new Integer(i);
    	          change(a, i, n, t);
    	          System.out.println("" + a[0][0] + a[0][1] + a[1][0] + a[1][1] + t[1]);
    	     }
    
    	public static void main(String s[])  { X q= new X(); }
    
    	     void change(int b[][],  int j,  Integer m,  Integer v[])
    	     {
    	          int c[][]= { {0, 9}, {8, 7} };
    
    	          b[1][1]= 5;
    	          b[0]= c[1];
    	          b= c;
    	          i= 6;
    	          m= new Integer(7);
    	          v[1]= m;
    	          m= new Integer(9);
    	          v= new Integer[3];
    	          v[0]= v[1]= v[2]= m;
    	     }
    	}
    
  2. 	class X
    	{
    		int k= 14, n= 15;
    	}
    
    	class Y extends X
    	{
    		int n;
    		Y()      { k= 41;  n= 42;  super.k= 43;  super.n= 44; }
    		Y(int i) { super(); n= i; super.n= 50; super.k= 51; }
    	}
    
    	class Z extends Y
    	{
    		int k;
    		Z()      { k= 20;  n= 21;  super.k= 22;  super.n= 23; }
    		Z(int i) { super(++i); k= 71;  n= 72;  super.k= 73;  super.n= 74; }
    	}
    
    	class W extends X
    	{
    		int n;
    
    		W() { k= 30;  n= 31;  super.k= 32;  super.n= 33; }
    		W(int i)  { k= i;  n= 61;  super.k= 62;  super.n= 63; }
    
    		public static void main(String a[])
    		{
    			X x= new X();
    			Y y= new Y(88);
    			Z z= new Z();
    			System.out.println("Z: " + z.k + z.n);
    			W w= new W();
    			System.out.println("W: " + w.k + w.n);
    
    			x= y;
    			System.out.println("XY: " + x.k + x.n);
    			x= z;
    			System.out.println("XZ: " + x.k + x.n);
    			x= w;
    			System.out.println("XW: " + x.k + x.n);
    		}
    	}
    
Home Page