object-orientation (part 2) data abstraction...

53
1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter 2019/2020 Programming Paradigms Lecture 15: Data Abstraction and Object-Orientation (Part 2)

Upload: others

Post on 21-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

1

Prof. Dr. Michael Pradel

Software Lab, University of StuttgartWinter 2019/2020

Programming Paradigms

Lecture 15:

Data Abstraction andObject-Orientation (Part 2)

Page 2: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

2 - 1

Wake-up Exercise

What does the following Java code print?

https://ilias3.uni-stuttgart.de/vote/0ZT9

class WakeUp {{System.out.println("a");

}WakeUp() {System.out.println("b");

}static {System.out.println("c");

}}// ...WakeUp w = new WakeUp();

Page 3: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

2 - 2

Wake-up Exercise

What does the following Java code print?

https://ilias3.uni-stuttgart.de/vote/0ZT9

class WakeUp {{System.out.println("a");

}WakeUp() {System.out.println("b");

}static {System.out.println("c");

}}// ...WakeUp w = new WakeUp(); Result: cab

Page 4: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

2 - 3

Wake-up Exercise

What does the following Java code print?

https://ilias3.uni-stuttgart.de/vote/0ZT9

class WakeUp {{System.out.println("a");

}WakeUp() {System.out.println("b");

}static {System.out.println("c");

}}// ...WakeUp w = new WakeUp(); Result: cab

Static initializer:Executed whenclass loaded

Page 5: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

2 - 4

Wake-up Exercise

What does the following Java code print?

https://ilias3.uni-stuttgart.de/vote/0ZT9

class WakeUp {{System.out.println("a");

}WakeUp() {System.out.println("b");

}static {System.out.println("c");

}}// ...WakeUp w = new WakeUp(); Result: cab

Instance initializer:Executed whenclass instantiated,just before theconstructor

Page 6: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

2 - 5

Wake-up Exercise

What does the following Java code print?

https://ilias3.uni-stuttgart.de/vote/0ZT9

class WakeUp {{System.out.println("a");

}WakeUp() {System.out.println("b");

}static {System.out.println("c");

}}// ...WakeUp w = new WakeUp(); Result: cab

Constructor:Executed last

Page 7: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

3

Overview

� Introduction

� Encapsulation and Information Hiding

� Inheritance

� Initialization and Finalization

� Dynamic Method Binding

� Mix-in Inheritance

� Multiple Inheritance

Page 8: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

4

Static vs. Dynamic Method Binding

� Given: Subclass that defines a methodalready defined in the superclass

� How to decide which method getscalled?

� Based on type of variable

� Based on type of object the variable refers to

Page 9: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

5 - 1

Exampleclass person { ... }class student : public person { ... }class professor : public person { ... }

void person::print_mailing_label() { ... }void student::print_mailing_label() { ... }void professor::print_mailing_label() { ... }

student s;professor p;

person *x = &s;person *y = &p;

s.print_mailing_label();p.print_mailing_label();

x->print_mailing_label();y->print_mailing_label();

Page 10: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

5 - 2

Exampleclass person { ... }class student : public person { ... }class professor : public person { ... }

void person::print_mailing_label() { ... }void student::print_mailing_label() { ... }void professor::print_mailing_label() { ... }

student s;professor p;

person *x = &s;person *y = &p;

s.print_mailing_label();p.print_mailing_label();

x->print_mailing_label();y->print_mailing_label();

Subclasses also define methodprint mailing label

Page 11: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

5 - 3

Exampleclass person { ... }class student : public person { ... }class professor : public person { ... }

void person::print_mailing_label() { ... }void student::print_mailing_label() { ... }void professor::print_mailing_label() { ... }

student s;professor p;

person *x = &s;person *y = &p;

s.print_mailing_label();p.print_mailing_label();

x->print_mailing_label();y->print_mailing_label();

Variables of subtypes

Variables of supertype

Page 12: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

5 - 4

Exampleclass person { ... }class student : public person { ... }class professor : public person { ... }

void person::print_mailing_label() { ... }void student::print_mailing_label() { ... }void professor::print_mailing_label() { ... }

student s;professor p;

person *x = &s;person *y = &p;

s.print_mailing_label();p.print_mailing_label();

x->print_mailing_label();y->print_mailing_label();

Methods ofsubclassescalled

Page 13: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

5 - 5

Exampleclass person { ... }class student : public person { ... }class professor : public person { ... }

void person::print_mailing_label() { ... }void student::print_mailing_label() { ... }void professor::print_mailing_label() { ... }

student s;professor p;

person *x = &s;person *y = &p;

s.print_mailing_label();p.print_mailing_label();

x->print_mailing_label();y->print_mailing_label();

Which methodsto call here?

Page 14: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

6

Static Method Binding

� Answer 1: Bind methods based ontype of variable

� Can be statically resolved (i.e., at compile time)

� Will call print mailing label of person

because x and y are pointers to person

Page 15: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

7

Dynamic Method Binding

� Answer 2: Bind methods based ontype of object the variable refers to

� In general, cannot be resolved compile time,

but only at runtime

� Will call print mailing label of student

for x because x points to a student project

(and likewise for y and professor)

Page 16: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

8

Pros and Cons

Static methodbinding

� No performance

penalty because

resolved at

compile-time

� But: Subclass

cannot control its

own state

Dynamic methodbinding

� Subclass can

control its state

� But: Performance

penalty of runtime

method dispatch

Page 17: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

9 - 1

Example (C++)

class text_file {char *name;// file pointerlong position;public:void seek(long offset) {// (...)

}};

class read_ahead_text_file : public text_file {char *upcoming_chars;public:void seek(long offset) {

// redefinition}

}

Page 18: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

9 - 2

Example (C++)

class text_file {char *name;// file pointerlong position;public:void seek(long offset) {// (...)

}};

class read_ahead_text_file : public text_file {char *upcoming_chars;public:void seek(long offset) {

// redefinition}

}

� Subclass needs to change

upcoming chars in seek

� But with static method binding,

cannot guarantee that it gets

called

Page 19: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

10 - 1

Support in Popular PLs

Staticmethodbinding

Dynamicmethodbinding

Page 20: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

10 - 2

Support in Popular PLs

Staticmethodbinding

Dynamicmethodbinding

Dynamic bindingfor all methods:Smalltalk,Python, Ruby

Page 21: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

10 - 3

Support in Popular PLs

Staticmethodbinding

Dynamicmethodbinding

Dynamic binding bydefault, but method orclass can be marked as notoverridable: Java, Eiffel

Page 22: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

10 - 4

Support in Popular PLs

Staticmethodbinding

Dynamicmethodbinding

Static binding by default,but programmer canspecify dynamic binding

Page 23: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

11

Java, Eiffel: Final/frozen Methods

� Mark individual methods (or classes)as non-overridable

� Java: final keyword for methods and classes

� Eiffel: frozen keyword for individual methods

Page 24: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

12

C++, C#: Overriding vs. Redefining

� C++: Superclass must mark methodas virtual to allow overriding

� C#: Subclass must mark method withoverride to override the superclassmethod

Override method:Dynamic binding

Redefine methodswith same name:Static binding

Page 25: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

13

Demo

Virtual.cpp

Page 26: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

14 - 1

Ada 95: Decide Per Reference

procedure print_mailing_label(r : person) is ...procedure print_mailing_label(s : student) is ...procedure print_mailing_label(p : professor) is ...

procedure print_label(r : person’Class) isbeginprint_mailing_label(r);-- calls appropriate overloaded version,-- depending on type of r at runtime

end print_label

Page 27: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

14 - 2

Ada 95: Decide Per Reference

procedure print_mailing_label(r : person) is ...procedure print_mailing_label(s : student) is ...procedure print_mailing_label(p : professor) is ...

procedure print_label(r : person’Class) isbeginprint_mailing_label(r);-- calls appropriate overloaded version,-- depending on type of r at runtime

end print_label

“Class-wide type” of person,i.e., person itself and all itssubtypes

Page 28: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

15

Abstract Methods and Classes

� Abstract method

� Implementation omitted

� Subclass must provide it

� Abstract class: Class with at least oneabstract method

Page 29: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

16

Demo

Abstract.java

Abstract.cpp

Page 30: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

17 - 1

Quiz: Method Binding

# Pseudo codeclass A:void foo():...

void bar():...

class B extends A:void bar():...

A x = new B()B y = xx.bar() # call 1y.bar() # call 2

https://ilias3.uni-stuttgart.de/vote/0ZT9

What is called when

a) PL always uses dynamicmethod binding

b) PL always uses staticmethod binding

c) PL always uses staticmethod binding unlessoverriding method marked withoverride

Page 31: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

17 - 2

Quiz: Method Binding

# Pseudo codeclass A:void foo():...

void bar():...

class B extends A:void bar():...

A x = new B()B y = xx.bar() # call 1y.bar() # call 2

https://ilias3.uni-stuttgart.de/vote/0ZT9

What is called when

a) PL always uses dynamicmethod binding

b) PL always uses staticmethod binding

c) PL always uses staticmethod binding unlessoverriding method marked withoverride

Page 32: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

17 - 3

Quiz: Method Binding

# Pseudo codeclass A:void foo():...

void bar():...

class B extends A:void bar():...

A x = new B()B y = xx.bar() # call 1y.bar() # call 2

https://ilias3.uni-stuttgart.de/vote/0ZT9

What is called when

a) PL always uses dynamicmethod binding

b) PL always uses staticmethod binding

c) PL always uses staticmethod binding unlessoverriding method marked withoverride

Page 33: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

17 - 4

Quiz: Method Binding

# Pseudo codeclass A:void foo():...

void bar():...

class B extends A:void bar():...

A x = new B()B y = xx.bar() # call 1y.bar() # call 2

https://ilias3.uni-stuttgart.de/vote/0ZT9

What is called when

a) PL always uses dynamicmethod binding

b) PL always uses staticmethod binding

c) PL always uses staticmethod binding unlessoverriding method marked withoverride

Page 34: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

18

Method Lookup

With dynamic method binding, how doesthe program find the right method tocall?

� Most common implementation:

Virtual method table (“vtable”)

� Every object points to table with its methods

� Table is shared among all instances of a class

Page 35: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

59

Page 36: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

20

Implementation of Inheritance

� Representation of subclass instance,including its vtable: Fully compatiblewith superclass

� Can use subclass instance like a superclass

instance without additional code

Page 37: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

60

Page 38: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

22 - 1

Implementation of Inheritance (2)

class foo { ... }class bar : public foo { ... }

foo F;bar B;

foo *q;bar *s;

q = &B;

s = &F;

Page 39: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

22 - 2

Implementation of Inheritance (2)

class foo { ... }class bar : public foo { ... }

foo F;bar B;

foo *q;bar *s;

q = &B;

s = &F;

Okay: References through q

will use prefixes of B’s dataspace and vtable

Page 40: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

22 - 3

Implementation of Inheritance (2)

class foo { ... }class bar : public foo { ... }

foo F;bar B;

foo *q;bar *s;

q = &B;

s = &F;Static semantic error: F lacksthe additional data and vtableentries of a bar object

Page 41: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

23

Overview

� Introduction

� Encapsulation and Information Hiding

� Inheritance

� Initialization and Finalization

� Dynamic Method Binding

� Mix-in Inheritance

� Multiple Inheritance

Page 42: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

24

Motivation

� Designing an inheritance tree withexactly one parent class: Difficult inpractice

� Examples

� Cat may be both Animal and Pet

� Widget in database maybe Sortable,

Graphable, and Storable

Page 43: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

25

Mix-in Inheritance

� Mix-in: Class-like abstraction thatprovides methods to be used in otherclasses without inheriting from themix-in

� A class can mix in multiple mix-ins

� Example:

� Combine mix-ins Animal and Pet into Cat

Page 44: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

26

Support in Popular PLs

Many variants of the mix-in idea

� Java: Interfaces are a lightweight version of

mix-ins

� Since Java 8: Default implementations of interface

methods

� Scala: “Traits”

� Ruby: include modules into a class

Page 45: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

27

Overview

� Introduction

� Encapsulation and Information Hiding

� Inheritance

� Initialization and Finalization

� Dynamic Method Binding

� Mix-in Inheritance

� Multiple Inheritance

Page 46: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

28 - 1

True Multiple Inheritance

� Sometimes, want to expand multipleclasses

� Allowed in some PLs, e.g., C++,Python, OCaml

� Example (C++):

class student : public person, public system_user {...

}

Page 47: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

28 - 2

True Multiple Inheritance

� Sometimes, want to expand multipleclasses

� Allowed in some PLs, e.g., C++,Python, OCaml

� Example (C++):

class student : public person, public system_user {...

}Gets all fields and methodsof both superclasses

Page 48: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

61

Page 49: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

30 - 1

Semantic Issues

� What if two parent classes provide a method with

the same name?

� What if two parent classes are both derived from

a common “grandparent”? Does the “grandchild”

have one or two copies of the grandparent’s

fields?

� How to represent objects in memory? Can each

parent be a prefix of the child?

Page 50: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

30 - 2

Semantic Issues

� What if two parent classes provide a method with

the same name?

� What if two parent classes are both derived from

a common “grandparent”? Does the “grandchild”

have one or two copies of the grandparent’s

fields?

� How to represent objects in memory? Can each

parent be a prefix of the child?Answers depend on the PL andgo beyond this lecture

Page 51: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

31 - 1

Quiz: Data Abstraction

Which of the following is true?

� Static and dynamic method binding are the same

in statically typed PLs.

� vtables store the fields of an object.

� A class can build upon multiple mix-ins.

� In Java, a class can directly extend multiple

classes.

https://ilias3.uni-stuttgart.de/vote/0ZT9

Page 52: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

31 - 2

Quiz: Data Abstraction

Which of the following is true?

� Static and dynamic method binding are the same

in statically typed PLs.

� vtables store the fields of an object.

� A class can build upon multiple mix-ins.

� In Java, a class can directly extend multiple

classes.

https://ilias3.uni-stuttgart.de/vote/0ZT9

Page 53: Object-Orientation (Part 2) Data Abstraction andsoftware-lab.org/teaching/winter2019/pp/lecture_data_abstraction2.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart

32

Overview

� Introduction

� Encapsulation and Information Hiding

� Inheritance

� Initialization and Finalization

� Dynamic Method Binding

� Mix-in Inheritance

� Multiple Inheritance 4