Hard Multiple Choice QuestionsΒΆ

These problems are harder than those that you will typically see on the AP CS A exam.

10-14-1: Assume that Base b = new Derived(); appears in a client program. What is the result of the call b.methodOne();?

public class Base
{
   public void methodOne()
   {
      System.out.print("A");
      methodTwo();
   }

   public void methodTwo()
   {
      System.out.print("B");
   }
}

public class Derived extends Base
{
   public void methodOne()
   {
      super.methodOne();
      System.out.print("C");
   }

   public void methodTwo()
   {
      super.methodTwo();
      System.out.print("D");
   }
}





10-14-2: If you have the following classes. Which of the following constructors would be valid for Point3D?

public class Point2D {
   public int x;
   public int y;

   public Point2D() {}

   public Point2D(int x,int y) {
      this.x = x;
      this.y = y;
   }
  // other methods
}

public class Point3D extends Point2D
{
   public int z;

   // other code
}

I.  public Point3D() {}
II. public Point3D(int x, int y, int z)
    {
       super(x,y);
       this.z = z;
    }
III. public Point3D(int x, int y)
     {
        this.x = x;
        this.y = y;
        this.z = 0;
     }