object vs. class! - politehnica university of...

4
Objects and Classes Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Introduction to Objects, Everything is an Object Dr. Cristina Marinescu An example in C... 2 Dr. Cristina Marinescu Same example in Java... 3 Dr. Cristina Marinescu Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of a hierarchy of classes united via inheritance relations. [G. Booch et al. Object-Oriented Analysis and Design with Applications. 3rd edition, 2007.] 4

Upload: others

Post on 17-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object vs. Class! - Politehnica University of Timișoaracs.upt.ro/~cristina/teaching/oop-en/ObjectsAndClasses.pdfsome class, and whose classes are all members of a hierarchy of classes

Objects and Classes

Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition)Introduction to Objects, Everything is an Object

Dr. Cristina Marinescu

An example in C...

2

Dr. Cristina Marinescu

Same example in Java...

3 Dr. Cristina Marinescu

Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of a hierarchy of classes united via inheritance relations.[G. Booch et al. Object-Oriented Analysis and Design with Applications. 3rd edition, 2007.]

4

Page 2: Object vs. Class! - Politehnica University of Timișoaracs.upt.ro/~cristina/teaching/oop-en/ObjectsAndClasses.pdfsome class, and whose classes are all members of a hierarchy of classes

Dr. Cristina Marinescu 5

Object vs. Class!

Dr. Cristina Marinescu

An Object has...

6

Identity(memory address)

Interface(known by its user)

Behavior(known by its implementer)

State(given by its attributes)

Dr. Cristina Marinescu 7 Dr. Cristina Marinescu 8

Page 3: Object vs. Class! - Politehnica University of Timișoaracs.upt.ro/~cristina/teaching/oop-en/ObjectsAndClasses.pdfsome class, and whose classes are all members of a hierarchy of classes

Dr. Cristina Marinescu 9 Dr. Cristina Marinescu

Access Specifiers

10

X

Dr. Cristina Marinescu

A Constructor

11

has the same name as the class it belongs to

does not return a value(neither void)

is called only when a class is instantiated

Dr. Cristina Marinescu 12

A constructor was added...

Page 4: Object vs. Class! - Politehnica University of Timișoaracs.upt.ro/~cristina/teaching/oop-en/ObjectsAndClasses.pdfsome class, and whose classes are all members of a hierarchy of classes

Dr. Cristina Marinescu 13

Static Members

Dr. Cristina Marinescu 14

Static Members

Dr. Cristina Marinescu 15

Final Members

Dr. Cristina Marinescu 16

Unified Modeling Language (UML) - an example