• Keine Ergebnisse gefunden

Advanced Aspects of Object-Oriented Programming (SS 2009) Practice Sheet 4

N/A
N/A
Protected

Academic year: 2022

Aktie "Advanced Aspects of Object-Oriented Programming (SS 2009) Practice Sheet 4"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

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.09

Deadline: 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

(2)

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

Referenzen

ÄHNLICHE DOKUMENTE

Refine the behavior of the getChar() method such that it returns the next character of the string if the position is not at the end and that it returns -1 if the reader is at the end

b) If the set of types / roles can be given at compile time and it will not change for an object during its lifecycle, it is usually a good idea to use subtyping and, if

b) Implement a StringReader. First add an interface equivalent to the BlankReader including the specification of the behavior. Second add an implementation of StringReader that

b) Extend the syntax as well as the semantics (static & dynamic) of StooJas to support static methods and give a detailed explanation for the necessary adjustments.. c) Extend

b) If the set of types / roles can be given at compile time and it will not change for an object during its lifecycle, it is usually a good idea to use subtyping and, if

a) Write a generic static method flip which takes an object of class Pair (see the slides of the lecture) and flips the elements of the given Pair object. Hint: In order to flip

a) Write a generic static method flip which takes an object of class Pair (see the slides of the lecture) and flips the elements of the given Pair object.. The method has the

• Guarantees of the type system cannot be used anymore.. b) If the set of types/roles can be given at compile time and it will not change for an object during its lifecycle, it