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

Post on 17-Jul-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

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

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

top related