SDSU CS 683 Emerging Technologies
Spring Semester, 2003
Java Self Test
    Course Web Site        
© 2003, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 21-Jan-03

Java Self Test

1. What is the difference between the “==” operator and the “equals()” method for String objects?

2. Explain the difference between "super" and "this".

3. What are the differences between an abstract class and an interface in Java?

4. What are the differences between checked and unchecked exceptions?


5. Show how to declare and create a triangular array in Java. That is first row of the array will be one column long, the second row will be two columns long, the k'th row will be k columns long .

6. Circle the assignment statements, "Line 1" through "Line 10", in the following code that illegally access a field.

package Exam;
public class Parent {
   protected String protectedVar = "Protected";
   String packageVar = "Package";
}
package Exam;
public class Uncle {
   public  void  SampleAccess( Parent parameter )  {
      parameter.protectedVar  =  "Line 1";
      parameter.packageVar  =  "Line 2";
   }
}
package Quiz;
public class Aunt {
   public  void  SampleAccess( Exam.Parent parameter)  {
      parameter.protectedVar  =  "Line 3";
      parameter.packageVar  =  "Line 4";  
   }
}
package  Quiz;
public class Child  extends  Exam.Parent {
   public  void  SampleAccess( Exam.Parent parentType,
                  Child  childType)  {
      parentType.protectedVar  =  "Line 5"; 
      parentType.packageVar  =  "Line 6"; 
      protectedVar  =  "Line 7";
      packageVar  =  "Line 8"; 
      childType.protectedVar  =  "Line 9";
       childType.packageVar  =  "Line 10"; 
   }
}

7. Given the code below, what is the output created by the statement "new Child()"?
class Parent 
{
   public Parent() {
      System.out.println( "Parent Constructor" );
   }
   
   {
      System.out.println( "Parent Block" );
   }
   
   static {
      System.out.println( "Parent Static" );
   }
}
class Child extends Parent {
   static {
      System.out.println( "Child Static" );
   }
      
   {
      System.out.println( "Child Block" );
   }
   public Child(){
      System.out.println( "Child Constructor" );
   }
}

8. Assume that the exception FooException is properly defined. What will be the output of compiling and executing the main method of the following class?

class ExceptionQuestionB {
   public void aMethod() throws FooException {
      try {
         System.out.println( "In aMethod" );
         throw new FooException();
      } catch ( FooException error ) {
         System.out.println( "in first catch" );
         throw new FooException();
      } finally {
         System.out.println( "Finally" );
         return;
      }
   }
   public static void main( String[] args ) {
      try {
         System.out.println( "Start" );
         ExceptionQuestionB x = new ExceptionQuestionB();
         x.aMethod();
         System.out.println( "After method" );
      } catch ( FooException error ) {
         System.out.println( "In handler" );
      }
      System.out.println( "End" );
   }
}

9. Given the class definition of the class File below, what implications does this have for the file structure, compiling the class, and using the class in a program?

package sdsu.whitney.io;
public class File {
   //code not shown
}

10. What are some of the major differences between the Vector and ArrayList classes?

Copyright ©, All rights reserved.
2003 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

    visitors since 21-Jan-03