CS535 Object-Oriented Programming & Design
Fall Semester, 1996
Doc 22, Exam
[To Lecture Notes Index]
San Diego State University -- This page last updated Nov 11, 1996
1) a) We have a class A which has a protected field P. Explain
where the protected field P is accessible and where it is not accessible.
b) We have a class A which has a field N, with no explicit access level
given. Explain where the field N is accessible and where it is not
accessible.
2) a) What is a NaN?
b) Under what conditions will a NaN be generated in Java?
3) What is a constructor? When are they called?
b) What is the role of a finalize method? When is it called?
4) What are the differences between an abstract class and an interface
in Java?
5) a) What makes an exception checked or unchecked?
b) How can a Java program treat an unchecked exception differently than
a checked exception?
6) Let a child and parent class both have a method, public void foo(),
with the same signature. The rules for determining which foo() is executed at
run time can be summarized as: "overridden methods are resolved dynamically".
Explain why hidden fields can not be resolved dynamically.
7) What is super? Give an example of when you would use "super".
8) We have two classes A and B. What relationship between A and B do the
following phrases indicate. Please indicate the role of A and B in the
relationship. For example: A is the parent of B.
a) Is-kind-of
b) is-analogous-to
c) has-a
9) True or False. A Java class A has a final field F. All objects
created from class A must have the same value for F.
True or False. An access of a non static method is always resolved
dynamically.
True or False. The average number of fields per class should be less
than 6.
True or False. If a child class constructor does not explicitly call
it's parent's constructor, then the parents constructor is not called when
creating a child object.
10) What is the result of compiling and if they compile executing the
following programs?
a)
class Test
{
public static void A()
{
int array[] = new int[5];
try
{
System.out.println( "Start Try" );
array[ 10 ] = 1;
}
catch ( Exception error )
{
System.out.println( "Exception " );
throw error;
}
finally
{
System.out.println( "Final Block" );
return;
}
}
public static void main( String args[] )
{
try { A(); }
catch (ArrayIndexOutOfBoundsException error )
{
System.out.println( "In Catch" );
}
System.out.println( "After try in main" );
}
}
b)
class Test
{
String message = "Global";
public static void A( String message)
{
message = message + "End";
}
public static void main( String args[] )
{
String message = "Main";
A( message );
System.out.println( message );
}
}
c)
class Parent
{
public Parent()
{
System.out.println( "Parent" );
}
public Parent( double value )
{
System.out.println( "Parent value " + value );
}
}
class Child extends Parent
{
public Child( String message )
{
System.out.println( "Child " + message );
}
public Child( double value )
{
System.out.println( "Child value " + value );
}
public static void main( String args[] )
{
Child A = new Child( 5.5 );
Parent B = new Child();
}
}