CS 683 Emerging Technologies Spring Semester, 2003 Java Self Test |
||
---|---|---|
© 2003, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 21-Jan-03 |
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"; } }
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" ); } }
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" ); } }
package sdsu.whitney.io; public class File { //code not shown }