Prof. Dr. A. Poetzsch-Heffter M.Sc. Yannick Welsch
University of Kaiserslautern Department of Computer Science Software Technology Group
Advanced Aspects of Object-Oriented Programming (SS 2009) Practice Sheet 4
Date of Issue: 12.05.09Deadline: 18.05.09 (until 10 a.m. as PDF via E-Mail)
Exercise 1 StoJas Extension (Repetition)
In this exercise, we are going to build extensions to the Java subsetStoJasthat was presented in the lecture.
a) Extend the syntax as well as the semantics (static & dynamic) ofStoJasto support a "do{ ... }while( ... )" statement and give a detailed explanation for the necessary adjustments.
b) Extend the syntax as well as the semantics (static & dynamic) ofStoJasto support interfaces and give a detailed explanation for the necessary adjustments. As for method declarations in classes, you can assume that method declarations in interfaces have exactly one parameter.
Exercise 2 Lecture Concepts
Give an example for the following statement:Programs with typing errors need not cause type errors.
Exercise 3 Covariance & Contravariance
a) Discuss the concept of Java’sChecked Exceptionswith respect to covariance and contravariance.
b) Which kind of guarantee is given byChecked Exceptions?
Exercise 4 Exceptions
What does each of the following programs do? Why?
i m p o r t j a v a . i o . I O E x c e p t i o n ;
p u b l i c c l a s s A r c a n e 1 {
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { t r y {
S y s t e m . o u t . p r i n t l n ( " H e l l ow o r l d " ) ; } c a t c h( I O E x c e p t i o n e ) {
S y s t e m . o u t . p r i n t l n ( " I ’ ven e v e rs e e np r i n t l nf a i l ! " ) ; }
} }
Arcane1.java
p u b l i c c l a s s A r c a n e 2 {
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { t r y {
/ / I f y o u h a v e n o t h i n g n i c e t o s a y , s a y n o t h i n g } c a t c h( E x c e p t i o n e ) {
S y s t e m . o u t . p r i n t l n ( " T h i sc a n ’ th a p p e n " ) ; }
} }
Arcane2.java
i n t e r f a c e Type1 {
v o i d f ( ) t h r o w s C l o n e N o t S u p p o r t e d E x c e p t i o n ; }
i n t e r f a c e Type2 {
v o i d f ( ) t h r o w s I n t e r r u p t e d E x c e p t i o n ; }
i n t e r f a c e Type3 e x t e n d s Type1 , Type2 { }
p u b l i c c l a s s A r c a n e 3 i m p l e m e n t s Type3 { p u b l i c v o i d f ( ) {
S y s t e m . o u t . p r i n t l n ( " H e l l ow o r l d " ) ; }
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { Type3 t 3 = new A r c a n e 3 ( ) ;
t 3 . f ( ) ; }
}
Arcane3.java