Programming in Java

OOP, Object, Class
蔡文能
交通大學資訊工程學系 tsaiwn@csie.nctu.edu.tw

交通大學資訊工程學系

Java

OOP-class

Outline
OOP programming Paradigm Object, Class Encapsulation and Information Hiding Inheritance (extension) vs. Contain Object-Oriented Technology: CRC, UML, . . . The Life Cycle of an Object Abstract Classes Interface Access Modifiers Nested Class Upcasting and Polymorphism
交通大學資訊工程學系 蔡文能 第2頁

Java

OOP-class

The Object-Oriented (OO) Programming Paradigm
Object-Oriented Programming (OOP) is one of the programming paradigms (典範) in computer science OOP is the dominant moden programming paradigm Object-Oriented Programming is well-known in the business world by the name of „Object Technology‟

交通大學資訊工程學系 蔡文能

第3頁

C. Pascal. C++.Java OOP-class Programming Paradigms Imperative Programming (FORTRAN. …)  The most common programming paradigm Functional Programming (LISP. 交通大學資訊工程學系 蔡文能 第4頁 . …) Simply using C++/Java constructs does not automatically lead to well-organized Object-Oriented Programs. Java. …) Logic Programming (Prolog) (Declarative programming language. 宣告式語言) Object-Oriented Programming (Smalltalk.

e..Java OOP-class Why OO Programming? Better concepts and tools to model and represent the real world as closely as possible (including concurrency. in Windows GUI) => model of reality => behavior modeling Better reusability & extensibility (inheritance) => reduce the time/cost of development Enhanced maintainability & improved reliability – “Encapsulation” and “Information Hiding”      Object only accessible through the external interface Internal implementation details are not visible outside Localized changes to implementation of classes Completeness: all required operations are defined Independent testing and maintenance 第5頁 Help writing good program more easily 交通大學資訊工程學系 蔡文能 .g.

Example of Objects John Custome r Mary Dog 238-49-1357 Account Object name Object „type‟ 交通大學資訊工程學系 蔡文能 第6頁 .Java OOP-class Objects An object is a thing.

Java OOP-class Classes A class (e. The object belongs to that class Instance-of Dog Dog Mary Dog DooDoo Dog 交通大學資訊工程學系 蔡文能 第7頁 .g. Dog) is a kind of mold or template to create objects (e...g. Mary and DooDoo) mold = 模型 = mould An object is an instance of a class.

Java OOP-class What Is an Object? These real-world objects all have states and behaviors. A common visual representation of a software object. Definition: An object is a software bundle of variables and related methods (function). 交通大學資訊工程學系 蔡文能 第8頁 .

The software bicycle would also have methods to  brake. 交通大學資訊工程學系 蔡文能 第9頁 . and  its current gear is the 5th gear.  change the pedal cadence. and  change gears.  its pedal cadence is 90 rpm.Java OOP-class Example: Bicycle The software bicycle's current state:  its speed is 10 mph.

and the same code to create many objects.Java OOP-class What Are Classes? Definition:  A class is a blueprint or prototype Defines the variables and methods common to all objects of a certain kind. 交通大學資訊工程學系 蔡文能 第10頁 .Software programmers use the same class. The Benefits of Classes  Reusability -.

個體) -.就是以前的變數 (Variable) 交通大學資訊工程學系 蔡文能 第11頁 ..Java OOP-class Objects vs.g. Classes Objects:  E.. Object (物件. Classes: or types  E. a real car. BMW-500 A Class is a blueprint or template of some objects Object is an Instance of some class.g.

Java ADT --. so the only operations (methods) possible are those provided in the type's definition which are known as interfaces.  The representation of objects of the type is hidden from the program units that use these objects. and operations on.Data Abstraction OOP-class An Abstract Data Type (ADT) is a user-defined data type that satisfies the following two conditions: (Encapsulation + Information Hiding)  The representation of. other program units can create objects of the type. ADT: 抽象資料型態 = 把資料以及對資料做處理 的操作(function)一起封藏在一個程式單元 交通大學資訊工程學系 蔡文能 第12頁 . objects of the type are defined in a single syntactic unit. also.

交通大學資訊工程學系 蔡文能 第13頁 .  Information hiding An object has a public interface that other objects can use to communicate with it.  The implementation details can change at any time without affecting other parts of the program. It is an ideal representation of an object.Java OOP-class Encapsulation (封藏) Hide the object's nucleus from other objects in the program. an object may wish to expose some of its variables or hide some of its methods. but  For implementation or efficiency reasons. Benefits:  Modularity The source code for an object can be written and maintained independently of the source code for other objects.

An object -.Java OOP-class Classes in Java A class -. 交通大學資訊工程學系 蔡文能 第14頁 .is a template that describes the data and behavior associated with instances of that class.instantiate a class you create an object. The data associated with a class or object is stored in variables. The behavior associated with a class or object is implemented with methods.  Methods are similar to the functions or procedures in C. An object is an instance of some class.

.. */ } public void changePedalCadence(int x) { /* */ } public void changeGear(int x) { /* . // a constructor! public void brake() { /* .Java OOP-class Class Bicycle in Java Not allowed in C++ Language public class Bicycle { private int speed = 10... private int currentGear = 5. private int pedalCadence = 90. */ } } 交通大學資訊工程學系 蔡文能 第15頁 .

Graphics. import java.Java OOP-class Class HelloWorld (Applet version) inherit Applet import java.drawString("Hello world!".awt.Applet. } } 交通大學資訊工程學系 蔡文能 第16頁 . 50.applet. 25). public class HelloWorld extends Applet { public void paint(Graphics g) { g.

 States: Gear & Speed  Behaviors: Brake & Accelerate Subclasses can  Add variables and methods.Java OOP-class What Is Inheritance? (extends) Subclasses inherit variables and methods from superclasses.  Override inherited methods. 交通大學資訊工程學系 蔡文能 第17頁 . Benefits:  Provide specialized behaviors  Reuse the code in the superclass  Abstract classes -.define "generic" behaviors.

println(“Arhh").println("Hello").out.out. private int weight = 0.Java OOP-class Mankind extends Animal Should be in different files public class Animal { private int height = 0. public void talk( ) { System.} } One Java file can only have one public class Mankind is-a Animal 交通大學資訊工程學系 蔡文能 第18頁 .} } public class Mankind extends Animal { private int iq = 120. public void talk( ) { System.

} }. int weight = 0. public: void talk( ) { System.Java OOP-class Mankind inherits Animal (C++) Classes can be in same file class Animal { int height = 0.out.println("Won").} } .println("Hello").out. "." is required to terminate a class 交通大學資訊工程學系 蔡文能 第19頁 . public: void talk( ) { System. In C++. class Mankind :public Animal { private: int iq = 120.

Java OOP-class Rectangle Contains Point Should be in different files public class Point { private int x = 0. } public class Rectangle { private int width = 0. private int y = 0. private Point origin = new Point(). } Car has-a Wheel 交通大學資訊工程學系 蔡文能 第20頁 . private int height = 0.

. . // a constructor! public Point(int xxx. Point p = new Point(44. this.78). private int y = 0.y 交通大學資訊工程學系 蔡文能 第21頁 .y = y.Java OOP-class Point and it's constructor public class Point { private int x = 0. int y) { x = xxx.x this. this. } } .

x = x. int height = 0. } } 交通大學資訊工程學系 蔡文能 第22頁 . } public Rectangle(int w. width = w. origin. int w. h). 0). Point origin. // four constructors public Rectangle() { origin = new Point(0.Java OOP-class Class may have many Constructors public class Rectangle { int width = 0. w. } public Rectangle(Point p) { origin = p. } public Rectangle(Point p. int h) { origin = p. } // a method for computing the area of the rectangle public int area() { return width * height. int h) { this(new Point(0. height = h.y = y. } // a method for moving the rectangle public void move(int x. int y) { origin. 0).

When object A wants object B to perform one of B's methods. Software objects interact and communicate with each other by sending messages to each other.Java OOP-class What Are Messages? Message in an object. 交通大學資訊工程學系 蔡文能 第23頁 . object A sends a message to object B.

 Messages can be sent and received between processes in the same machine or in different machines. 2.changeGears(lowerGear)  Message passing supports all interactions between objects. 交通大學資訊工程學系 蔡文能 第24頁 . 3. The object to whom the message is addressed (Your Bicycle).Java OOP-class Messaging Three components comprise a message: 1. Any parameters needed by the method (lowerGear). The name of the method to perform (changeGears). Benefits: yourBicycle.

Java OOP-class Object-Oriented Technology Object-Oriented Analysis (OOA)  Goal: Understand the domain Object-Oriented Design (OOD)  Goal: Design a solution. a model of the domain in which the desired activities occur Object-Oriented Programming (OOP)  Goal: Implement the solution Note: A Good Design is 2/3 Before You Hit the Keyboard 交通大學資訊工程學系 蔡文能 第25頁 .

go to OOD. not a waterfall Design is an iterative activity  Start in OOA.Java OOP-class It's a process. forget something in OOA  Get to OOP. realize you didn't understand something and go back The stages are there to identify emphases  For example. OOA is TOTALLY Language-Independent Waterfall model 是早期軟工強掉的軟體發展過程 emphases = 重點 = emphasis 的複數 交通大學資訊工程學系 蔡文能 第26頁 .

Java OOP-class Object-Oriented Analysis Step one: Brainstorming Candidate Classes  Write down all the objects that related Focus on the nouns Good objects have attributes and services  Now. filter the candidates Deal with the interface later (Not part of the domain) Are some candidates attributes of others? Are some subclasses of others? (Inheritance) Are some instances of others? 交通大學資訊工程學系 蔡文能 第27頁 .

they add some very useful insights throughout a development. Data fields (attributes) 寫在背面 交通大學資訊工程學系 蔡文能 第28頁 .Java OOP-class OOA: CRC Cards Step two: Write CRC cards and work through scenarios  Class-Responsibility-Collaborator Cards (Cunningham and Beck)  Just 3x5 cards •Although CRC is not part of UML.

Java OOP-class How to use CRC Cards Make one for each candidate class Invent scenarios: What should these objects do? Play the cards     Lay down the card that starts the scenario Write down its responsibility Add collaborator objects to help with that responsibility Pick up cards as they leave the scenario 交通大學資訊工程學系 蔡文能 第29頁 .

Java OOP-class Why CRC Cards? Help you identify objects and their responsibilities Help you understand interactions between objects Cards form a useful record of early design activity Cards work well in group situations and are understandable by non-technical stakeholders 交通大學資訊工程學系 蔡文能 第30頁 .

Java OOP-class Object-Oriented Design Step one: Create a UML class diagram of your objects Step two: Create a detailed description of the services to be performed  Peter Coad's "I am a Count. sequence. I know how to increment…"  Activity. or collaboration UML diagrams 交通大學資訊工程學系 蔡文能 第31頁 .

Deployment. Maintenance.org)  以UML Model(塑模)為基礎  支援完整開發週期: Analysis.Java OOP-class MDA-Model Driven Architecture? A New Way to Specify and Build Systems  2001年由OMG制定的新開發架構 (http://www. Evolution & Integration with later systems (改進與後 續整合)  內建協同運作性及跨平台性  降低開發初期成本及提高ROI (投資報酬)  可套用至你所使用的任何環境: Programming language  Network Operating System  Middleware 交通大學資訊工程學系 蔡文能 第32頁 .omg. Implementation. Design.

org There have been O-O gurus for many years Three of them worked together to define UML (“Three amigos”: Booch.Java OOP-class Unified Modeling Language http://www.UML. many forms of notation  It's even provable! (with OCL) (Object Constrain Language) amigos = friends 交通大學資訊工程學系 蔡文能 第33頁 . Jacobson) Has now been approved as a standard by the Object Management Group (OMG) Very powerful.org http://www. Rumbaugh.omg.

5 UML 1. Jan 1997 UML partners Web .9 Minor revision 1999 OMG Acceptance.June 1996 OOPSLA 95 交通大學資訊工程學系 蔡文能 Unified Method 0.1 UML 1.Java OOP-class History of the UML( http://www. Sept 1997 First submission to OMG.0 UML 1.0 UML 0.8 OOSE Booch method OMT 第34頁 Other methods .org/ ) Approved 2004 Minor revision 2003 Minor revision 2001 Public Feedback UML 2.4 UML 1.3 UML 1. Nov 1997 Final submission to OMG.uml.

Java OOP-class UML 常用的 Diagrams Use case diagrams Class diagrams  Functional behavior of the system as seen by the user. a flowchart. i.e.  Static structure of the system: Objects. and Associations. Activity diagrams Sequence diagrams  Dynamic behavior between actors and system objects. Statechart diagrams  Dynamic behavior of an individual object as FSM (有限狀態機).  Dynamic behavior of a system. in particular the workflow. Attributes. 交通大學資訊工程學系 蔡文能 第35頁 .

Java OOP-class UML 12 Diagrams Behavior : Structural:  Use Case  Sequence  Collaboration  State Chart  Activity  Class  Component  Deployment  Object Model Management:  Packages (class diagram contains packages)  Subsystems (class diagram contains subsystems)  Models (class diagram contains models) 第36頁 交通大學資訊工程學系 蔡文能 .

Resulted from the convergence of notations from three leading Object-Oriented methods: Booch method (by Grady Booch) OMT (by James Rumbaugh) OOSE (by Ivar Jacobson) You can model 80% of most problems by using about 20% of the UML UML is a “blueprint” for building complex software 交通大學資訊工程學系 蔡文能 第37頁 .Java OOP-class So. What is UML? 軟體工程師共通的語言 UML is a Unified Modeling Language UML is a set of notations. not a single methodology Modeling is a way of thinking about the problems using models organized around the real world ideas.

). Nodes represent entities in some domain (in our case. methods. sender/receiver)  Containment represents belonging (e. use cases in package) Higraphs are an extension to the familiar Directed Graph structure where nodes are connected by edges to other nodes. packages. classes. classes.g. 交通大學資訊工程學系 蔡文能 第38頁 . etc.g. states)  Arcs are relationships among entities (e.g.Java OOP-class UML Core Conventions Rectangles are classes or instances Ovals are functions or use cases Types are denoted with non-underlined names  SimpleWatch  Firefighter Instances are denoted with an underlined names  myWatch:SimpleWatch  Joe:Firefighter Diagrams are higraphs  Nodes are entities (e.

(強調 what. 但暫不管 how) 交通大學資訊工程學系 蔡文能 第39頁 . WatchUser SetTime WatchRepairPerson ChangeBattery Use case Use case diagrams represent the functionality of the system from user’s point of view. It is highly detailed in describing what is required but is free of most implementation details and constraints.Java OOP-class Use Case Diagram examples Package Actor ReadTime SimpleWatch A use case documents the interaction between the system user and the system.

Java OOP-class Class Diagram : a simple Watch Class Multiplicity SimpleWatch 1 2 PushButton state push() release() 1 LCDDisplay blinkIdx blinkSeconds() blinkMinutes() blinkHours() stopBlinking() referesh() 1 1 1 2 Battery load() 1 Time now() Association Attributes Operations Class diagrams represent the structure of the domain or system 交通大學資訊工程學系 蔡文能 第40頁 .

Java Sequence Diagram Object :WatchUser :SimpleWatch :LCDDisplay pressButton1( ) pressButton1() pressButton2() pressButtons1And2() blinkHours() blinkMinutes() OOP-class :Time incrementMinutes() refresh() commitNewTime() Activation stopBlinking() Activation Message Sequence diagrams represent the behavior as interactions It shows sequence of events for a particular use case Object diagram with numbered messages Sequence numbers of messages are nested by procedure call 交通大學資訊工程學系 蔡文能 Collaboration Diagram 第41頁 .

Java State chart Diagrams for the watch OOP-class Initial state Blink Hours button2Pressed Event button1&2Pressed State Increment Hours Transition button1&2Pressed button1Pressed button2Pressed Blink Minutes Increment Minutes button1Pressed button1&2Pressed Stop Blinking Blink Seconds button2Pressed Increment Seconds Final state 交通大學資訊工程學系 蔡文能 FSM: Finite State Machine 第42頁 .

像流程圖 第43頁 .Java Activity Diagrams Handle Incident Document Incident OOP-class An activity diagram shows flow control within a system Archive Incident An activity diagram is a special case of a state chart diagram in which states are activities (“functions”) Two types of states:  Action state: Cannot be decomposed any further Happens “instantaneously” with respect to the level of abstraction used in the model  Activity state: Can be decomposed further The activity is modeled by another activity diagram 交通大學資訊工程學系 蔡文能 描述Business process或use case的操作流程.

and inheritance relationships  Multiplicity and navigation indicators  Role names Objects described by classes collaborate  Class relations → object relations  Dependencies between classes 交通大學資訊工程學系 蔡文能 第44頁 .Java OOP-class Classes in UML Classes describe objects  Behaviour (member function signature / implementation)  Properties (attributes and associations)  Association. aggregation. dependency.

arguments and methods are specified by visibility name : type 交通大學資訊工程學系 蔡文能 第45頁 .Java UML Class Visibility shown as + OOP-class public private # protected Class name Data members (attributes) Instance methods Class method (static) Arguments Return types Data members.

Java OOP-class Class Attributes Attributes are the instance data members and class data members Class data members (underlined) are shared between all instances (objects) of a given class Data types shown after ":" Class name Attribute compartment Visibility shown as + public private # protected 交通大學資訊工程學系 蔡文能 visibility name : type 第46頁 .

no need for a class instance (object) 交通大學資訊工程學系 蔡文能 Operations compartment 第47頁 .Java OOP-class Class Operations (Interface) Operations are the class methods with their argument and return types Public (+) operations define the class interface Class methods (underlined) can only access to class data members.

Java OOP-class Template Classes Type parameter(s) Operations compartment as usual. but may have type parameter instead of concrete type Generic classes depending on parametrised types 交通大學資訊工程學系 蔡文能 第48頁 .

behaviour and data members B can extend A. add new data members or member functions B depends on A.e. A knows nothing about B 第49頁 .Java OOP-class Class Inheritance Base class or super class Arrow shows direction of dependency (B inherits A) Derived class or subclass → → → 交通大學資訊工程學系 蔡文能 B inherits A's interface. i.

behaviour and data members of all its base classes implements extends Extension and overriding works as before B implements the interface A and is also a "countable" class since it inherits class Countable 交通大學資訊工程學系 蔡文能 class B extends Countable implements A { /*…*/ } 第50頁 .Java OOP-class Multiple Inheritance (Java) The derived class inherits interface.

Java OOP-class How can two classes be related? Generalization-specialization or IsA  NamedBox IsA Box  Diagram: Triangle on the relationship line Association or HasA  Box HasA Pen  Diagram: Just a relationship line  Aggregation is a part-whole relationship Diagram: Diamond on the line Dependency or TalksTo  Dependency is sort of temporary HasA Diagram: Dashed line in UML 交通大學資訊工程學系 蔡文能 第51頁 .

omg.Java OOP-class Recommended Book: UML Distilled Serious O-O designers DO use UML UML Distilled by Martin Fowler is a great practical introduction to UML Official UML book series published by Addison-Wesley http://www.org 交通大學資訊工程學系 蔡文能 第52頁 .

Java OOP-class UML Tools Most complete tool: Rational Rose. ObjectPlant. http://www. 交通大學資訊工程學系 蔡文能 第53頁 . Posiden.rational. available on CD/CoWeb  Argo-UML. http://www.com Lots of others  Together by Object International.oi.com  BOOST (Basic Object-Oriented Support Tool) by Noel Rappin. etc.

Java OOP-class O O Features Encapsulation Information Hiding (Data Hiding) Object Based Inheritance Polymorphism Object Oriented ( 物件導向 ) ( 個體導向 ) 交通大學資訊工程學系 蔡文能 For Software Reuse 第54頁 .

Java OOP-class OO features   Encapsulation Information Hiding 抽象化的概念以前 就有: 函數/副程式 The concept of abstraction is fundamental in programming Subprogram / function  process abstraction ADT  Data abstraction 增加:  Inheritance  Polymorphism Software Reuse 交通大學資訊工程學系 蔡文能 第55頁 .

Java OOP-class Class elements 交通大學資訊工程學系 蔡文能 第56頁 .

The method name must exactly match the class name. 2. There must not be a return type declared for the method. Java has NO destructor. 交通大學資訊工程學系 蔡文能 第57頁 . To write a constructor you must adhere to two rules : 1.Java OOP-class Constructors For purpose of initialization objects have special methods called constructors.

? What If you write one constructor ? 交通大學資訊工程學系 蔡文能 第58頁 .Java OOP-class The Default Constructor Every class has a constructor. If you don‟t write one Java provides one for you. This constructor takes no arguments and has an empty body.

/*注意 分號 */ int main( ) { struct Student x.score[?] */ } 交通大學資訊工程學系 蔡文能 第59頁 .name. strcpy(x. /* 最多修13 科 */ }.Java OOP-class Struct – 自訂資料型別 in C/C++ #include <stdio. "張大千") . /* C++ 和 C99 不用寫 struct */ x.h> Why using struct ? struct Student { Java has no struct long sid. /*注意 */ /* 用 loop 把成績讀入 x. char name[9].sid = 123. /* 四個Big5中文 */ float score[13].

Java OOP-class Struct vs. int main( ) { private Student x.sid = 123.sid << endl.h> class Student { // 若改為 struct Student { …? long sid. Class in C++ (1/2) #include <iostream. // compile錯. x. // compile錯 return 0. }. } 交通大學資訊工程學系 蔡文能 第60頁 . access not allowed cout << "== " << x.

} setId( long xx) { sid = xx. Class in C++ (2/2) #include <iostream.showNumber( ) << endl. // OK. int main( ) { Student x. x. } }. 透過 public function setId( ) cout << " == " << x.setId(123). public: showNumber( ) { return sid.Java OOP-class Struct vs. // OK return 0. } 交通大學資訊工程學系 蔡文能 第61頁 .h> class Student { // private: long sid. y.

} 交通大學資訊工程學系 蔡文能 使用 default constructor 沒有參數 Student y(456) .Java OOP-class Class(Object) Constructor 1/4 (C++) #include <iostream. public: showNumber( ) { return sid. // Error x. 有問題! 因為 default constructor 就是不能有參數 第62頁 .h> class Student { // private: long sid.setId(123). int main( ) { Student x. } }. } setId( long xx) { sid = xx. return 0. m. Student y(456). n.

有兩種解決方法: return 0. public: showNumber( ) { return sid.Java OOP-class Class(Object) Constructor 2/4 (C++) #include <iostream.setId(123). 現在OK了 } 交通大學資訊工程學系 蔡文能 第63頁 . } setId( long xx) { sid = xx. } 加入這constructor }. // OK now 不能用了 – x. } Student(long x) { sid = x.h> class Student { // private: long sid. Student y(456) . 有問題! Student x. // Error 因為 default constructor Student y(456). int main( ) { Student x.

} Student(long x=0) { sid = x.h> class Student { // private: long sid. } Student x.Java OOP-class Class(Object) Constructor 3/4 (C++) #include <iostream. // OK x. 有問題 解決方法一 使用Default 參數 第64頁 交通大學資訊工程學系 蔡文能 . public: showNumber( ) { return sid. return 0. int main( ) { Student x. } }. y(456). } setId( long x) { sid = x.setId(123).

} Student( ) { sid=0. y(456). } }. 解決方法之二 } 交通大學資訊工程學系 蔡文能 再加一個沒參數的constructor 第65頁 .h> class Student { // private: long sid. int main( ) { Student x. 有問題 return 0. } setId( long xx) { sid = xx. cout << "Hehehe\n". Student x. cout << "Haha\n". public: showNumber( ) { return sid.setId(123). // OK x. } Student(long x) { sid = x.Java OOP-class Class(Object) Constructor 4/4 (C++) #include <iostream.

Java OOP-class More about Classes Properties:  Single implementation inheritance .implements All classes inherit from java.extends The inherited class is called “superclass”.Object Scope: (next slide) 交通大學資訊工程學系 蔡文能 第66頁 .lang.  Multiple interface inheritance .

Java OOP-class Scope 交通大學資訊工程學系 蔡文能 第67頁 .

After this statement. Rectangle rect = new Rectangle(100. In Java. The new operator creates the object. and the constructor initializes it. rect refers to a Rectangle object. 200). classes and interfaces can be used as data types. The new operator requires a argument: a call to a constructor.200). 交通大學資訊工程學系 蔡文能 第68頁 .  Instantiating an Object The new operator allocates memory for a new object.  Declaring an Object Object declarations can also appear alone : Rectangle rect. The new operator returns a reference to the newly created object. Declarations do not create new objects. new Rectangle(100.Java OOP-class The Life Cycle of an Object – Creation (I) Creating Objects Rectangle rect = new Rectangle().

Java

OOP-class

The Life Cycle of an Object -- Creation (II)
 Initializing an Object
Constructors have the same name as the class and have no return type.
public public public public Rectangle(Point p) Rectangle(int w, int h) Rectangle(Point p, int w, int h) Rectangle()

Example:
Rectangle rect = new Rectangle(100, 200); Rectangle rect = new Rectangle( new Point(44,78));

A constructor can takes no arguments, is called a no-argument constructor. If a class does not define any constructors, Java provides a noargument constructor, called the default constructor.

交通大學資訊工程學系 蔡文能

第69頁

Java

OOP-class

The Life Cycle of an Object -- Access
Using Objects
 Referencing an Object's Variables
objectReference.variable

Example:
int areaOfRectangle = rect.height * rect.width;

 Calling an Object's Methods
objectReference.methodName(); or objectReference.methodName(argumentList);

Example:
rect.move(15, 37); int areaOfRectangle = new Rectangle(100, 50).area();

交通大學資訊工程學系 蔡文能

第70頁

Java

OOP-class

The Life Cycle of an Object – Cleanup
Cleaning Up Unused Objects
 An object is eligible for garbage collection when there are no more references to that object.  The Garbage Collector
Automatically frees an object, if not referenced. prevents memory leaks claimed delay ~200ms for 4MB Mark-sweep garbage collector The garbage collector runs in a low-priority thread.
 When the system runs out of memory.  In response to a request from a Java program.  When the system is idle.

交通大學資訊工程學系 蔡文能

第71頁

need to close it. Example public class Rectangle { public Point origin. the system will call this first. super. The finalize method is a member of the Object class. . when freed. protected void finalize() throws Throwable { origin = null. Scenario: For a file object. Problem: Make the internal JVM implementation for memory management very complicated. such as native peers. . } } 交通大學資訊工程學系 蔡文能 第72頁 .finalize().Java OOP-class Finalization When freeing an object. Implementing a finalize method to release resources that aren't under the control of the garbage collector. .

Java

OOP-class

Example for Overriding (1/2)
class Point { protected int x,y; Point(int x, int y) {this.x = x; this.y = y;} void draw(){ System.out.println(“Point at”+x+”,”+y); }; }

Subclassing:
class Cpoint extends Point{ private Color c; Cpoint(int i, int j, Color c){ super(i,j); this.c =c; };

void draw(){
System.out.println(“Color Point at ” + i + ”,” + j + ”,” + c); }; }

交通大學資訊工程學系 蔡文能

第73頁

Java

OOP-class

Example for Overriding (2/2)
class PointApp{ public static void main(){ Point p = new Point(5,5); Cpoint cp = new Cpoint(1,1,Red); p.draw(); cp.draw(); p = cp; p.draw(); // call Point’s draw() or Cpoint’s draw()? } }

Overriding 不是 overloading !
交通大學資訊工程學系 蔡文能 第74頁

Java

OOP-class

Overloading
A Method's Name (function name)
 Java supports method name overloading so that multiple methods can share the same name.
class DataRenderer { void draw(String s) { . . . } void draw(int i) { . . . } void draw(float f) { . . . } }

 Overloaded methods are differentiated by the number and type of the arguments.  A subclass may override a method in its superclass.
The overriding method must have the same name, return type, and parameter list as the method it overrides.

Java 不可以 operator overloading
交通大學資訊工程學系 蔡文能 第75頁

• Abstract classes can not be instantiated! So the following is illegal: MotorVehicle m = new MotorVehicle. An abstract method is decorated with an extra “abstract” keyword. only declared.Java OOP-class Abstract Classes in Java • Abstract classes created using the abstract keyword: public abstract class MotorVehicle { … } • In an abstract class. // 錯 ! // 抽象類別不能拿來生出物件 //因為抽象的東西根本不存在 交通大學資訊工程學系 蔡文能 第76頁 . several abstract methods are declared. The body of the method is then implemented in subclass. An abstract method is not implemented in the class.

的函數 /* … */ } • So MotorVehicle can NOT be instantiated (ie.) 交通大學資訊工程學系 蔡文能 第77頁 . // 抽象函數.} //這個不是抽象函數! public abstract void gas( ).Java OOP-class Abstract methods • Abstract methods are declared but do not contain an implementation. can not be used to create an object.在 C++ 是寫 =0. the MotorVehicle class may have an abstract method gas( ): public abstract class MotorVehicle { private double speed.. maxSpeed. void accToMax( ) { speed = maxSpeed. • For example.

.. } } 交通大學資訊工程學系 蔡文能 第78頁 . void push(Object o) { elems[top++] = o. } Object pop() { . // declare ..Java OOP-class Example of Abstract Classes (1/2) Example: abstract class Stack { abstract void push(Object o)... } public class ArrayStack extends Stack { ..... } } class LinkedStack extends Stack { .. } Object pop() { return elems[--top]. // declare elems[] and top.. abstract Object pop().... void push(Object o) { .

push(x). o2 = s.. testStack(as). 交通大學資訊工程學系 蔡文能 第79頁 .. . } .Java OOP-class Example of Abstract Classes (2/2) // ============================== Another file . s.. ArrayStack as = new ArrayStack(). o1 = s... // check if o1 == y && o2 == x.pop()..push(y)...pop(). s. static public int testStack(Stack s) { ..

• An interface can also have fields. (implements) • To declare an interface: public interface ImportTax { public double calculateTax( ). but the fields must be declared as final and static. • All methods are abstract implicitly.Java OOP-class Interfaces Defines a set of methods that a class must implement • An interface is like a class with nothing but abstract methods and final and static fields (constants). • Interface can be added to a class that is already a subclass of another class. } 交通大學資訊工程學系 蔡文能 第80頁 .

} } 交通大學資訊工程學系 蔡文能 第81頁 .Java OOP-class Example of Interfaces (1/2) interface Stack { void push(Object o)... } Object pop() { return elems[--top]. Object pop(). } } class LinkedStack implements Stack { .. } public class ArrayStack implements Stack { .. void push(Object o) { . void push(Object o) { elems[top++] = o..... } Object pop() { ..... // declare .. // declare elems[] and top..

pop(). s. . o1 = s. o2 = s...push(y). 交通大學資訊工程學系 蔡文能 第82頁 .pop().push(x). } ...Java OOP-class Example of Interfaces (2/2) //============================== Another file ... s. static public int testStack(Stack s) { . testStack(as). // check if o1 == y && o2 == x... ArrayStack as = new ArrayStack()..

• An abstract class can not be instantiated but can be extended (subclassed). Each abstract method is prefixed with the keyword “abstract”. • An interface contains only abstract methods and constants. • An interface can only be implemented. 交通大學資訊工程學系 蔡文能 第83頁 . Each abstract method is not prefixed with the keyword “abstract”.Java OOP-class Difference between Abstract Class and Interface • An abstract class is a class containing several abstract methods.

或 =0.Java OOP-class How C++ Deals with Interfaces or Abstract Classes Use virtual functions: class Stack { virtual void push(void* o) = NULL. // NULL 就是 0 } // 注意 C++ 只有 virtual函數才可寫 = NULL. 的 virtual function叫做pure virtual function // Java 則永遠自動 virtual What are the internal designs?  Key for the designs of COM/DCOM (MicroSoft) 交通大學資訊工程學系 蔡文能 第84頁 . virtual void* pop() = NULL. // 寫 = NULL. 或 = 0.

s.Java OOP-class Example for C++ class ArrayStack : Stack { ... } . // declare elems[] and top. s. .... } } ============================== Another file . } Object pop() { return elems[--top]. // declare . ArrayStack as = new ArrayStack()..... void push(Object o) { elems[top++] = o.pop().... o2 = s.... } Object pop() { .. 交通大學資訊工程學系 蔡文能 第85頁 . testStack(as). o1 = s.push(x). void push(Object o) { ..push(y).. // check if o1 == y && o2 == x.... } } class LinkedStack : Stack { . int testStack(Stack s) { ..pop()..

e.. ..sys.Networking support for Socket & URL-based objects  java.. Exception.  java. BitSet. import java.Object.Abstract window toolkit defines a simple.io .net . Thread. Regexp. i. restricted windowing API  java.Java OOP-class Packages and Library Organize class name space Hierarchical division must be reflected in directory structure.InputStream. .sys. OutputStream.util . class Login { /* in fact...Hashtable. Debugging.  java.Compilation.tools ...JDK  java. package cyc. Documentation  … 交通大學資訊工程學系 蔡文能 第86頁 .Login */ } Default packages (library) -.*.lang . Vector. String.awt . this is cyc.io.  java.

Rectangle 交通大學資訊工程學系 蔡文能 第87頁 .Rectangle The name of the Rectangle class in the java.company.package  com.awt.awt package is really java.company.package Java 並沒有 graphics.Rectangle Convention  com.Java OOP-class Naming a Package The name of the Rectangle class in the graphics package is really graphics.region.

synchronized: described in Thread transient: data that is not persistent 交通大學資訊工程學系 蔡文能 第88頁 .Java OOP-class Access Modifiers (no keyword): class/package access (different from C++) I. package available public: world access (same as C++) private: class access (same as C++) protected: subclassing access(same as C++) static: only one copy for all instances abstract: left unimplemented final: not overridden native: methods implemented in native code..e.

Java OOP-class Comparisons Controlling Access to Members of a Class Specifier private protected public package Class X X X X Subclass Package X X X X X World X 注意西方人是打 X 表示勾選! 交通大學資訊工程學系 蔡文能 第89頁 .

int ave = ts. Static method . y. x = 3. Static variable static int peek() { j += 2.k 交通大學資訊工程學系 蔡文能 第90頁 . static { j = j*5. z. } } Static method j.. } // done when loading class public static void main(String[] args) { .Java OOP-class Static static:  only one copy for the class and all instances  Usually used as a global variable (even no instances) class TestStatic { int x... } static int j = 0.average(). int average() {return (x+y+z)/3. // error! } Static block static int k = peek(). TestStatic ts = new TestStatic()..

交通大學資訊工程學系 蔡文能 第91頁 . .  Allow for JIT to optimize. . A final local variable that has been declared but not yet initialized is called a blank final. final int blankfinal. . Final methods: methods that cannot be overridden.red. final Color red = Color. Such variables are similar to constants in other programming languages.Java OOP-class Final Final variables:  The value of a final variable cannot change after it has been initialized. blankfinal = 0.  Prevent clients from overriding.

Volatile transient : used in object serialization to mark member variables that should not be serialized.Java OOP-class Transient vs. 交通大學資訊工程學系 蔡文能 第92頁 . volatile : used to prevent the compiler from performing certain optimizations on a member.

class EnclosingClass{ .  For example. even for private.Java OOP-class Nested Class A nested class is a class that is a member of another class. } } Define a class within another class when the nested class makes sense only in the context of its enclosing class. . A nested class has a special privilege:  It has unlimited access to its enclosing class's members. Just like a method that can access private. . class ANestedClass { . 交通大學資訊工程學系 蔡文能 第93頁 . a text cursor makes sense only in the context of a particular text component. . .

. } class InnerClass { . . . 交通大學資訊工程學系 蔡文能 第94頁 . /* static is wrong in this inner class */ } } A static nested class is called: a static nested class. static class AStaticNestedClass { .  A static nested class cannot refer directly to instance variables or methods defined in its enclosing class A nonstatic nested class is called an inner class.  Because an inner class is associated with an instance.  An inner class is associated with an instance of its enclosing class and has direct access to that object's instance variables and methods.Java OOP-class Types of Nested Class class EnclosingClass{ . it cannot define any static members itself. . . .

class InnerClass { . . . Inner To help differentiate the terms nested class and inner class:  The term "nested class" reflects the syntactic relationship between two classes. . An instance of InnerClass can exist only within an instance of EnclosingClass. class EnclosingClass { .Java OOP-class Nested vs. It has direct access to instance variables and methods of its enclosing instance. . the term "inner class" reflects the relationship between instances of the two classes. } } 交通大學資訊工程學系 蔡文能 第95頁 .  In contrast.

Java OOP-class Example: Adaptor Using an Inner Class to Implement an Adapter import java. } public Object nextElement() { if (!hasMoreElements()) throw new NoSuchElementException()..elementAt(currentItem--). } } } 交通大學資訊工程學系 蔡文能 第96頁 ..size() .. // .util. import java. code for Stack's methods and constructors not shown.util. else return items.util.Vector items.Enumeration. public Enumeration enumerator() { return new StackEnum(). } class StackEnum implements Enumeration { int currentItem = items. public class Stack { private java..1.NoSuchElementException. public boolean hasMoreElements() { return (currentItem >= 0).

. } }. } public Object nextElement() { if (!hasMoreElements()) throw new NoSuchElementException(). . public boolean hasMoreElements() { return (currentItem >= 0).Java OOP-class Anonymous Class You can declare an inner class without naming it.//code for Stack's methods and constructors not shown.size() .) public class Stack { private Vector items. else return items. public Enumeration enumerator() { return new Enumeration() { int currentItem = items. } } 交通大學資訊工程學系 蔡文能 第97頁 .1.. Example: (Rewrite the previous slide..elementAt(currentItem--)..

交通大學資訊工程學系 蔡文能 第98頁 . because of the way inheritance trees are drawn with the base class at the top. .Java OOP-class Upcasting and Polymorphism(1/4) • Upcasting: Taking an object reference and treating it as a reference to its base type is called upcasting.

Java OOP-class Upcasting and Polymorphism class Shape { void draw( ) {} void erase( ) {} } (2/4) • Polymorphism: In Java.erase( )"). the principle that the actual type of the object determines the method to be called is called polymorphism.out.draw( ) "). } void erase( ) {System. Shape draw() erase() Circle draw() erase() Square draw() erase() Triangle draw() erase() class Circle extends Shape { void draw( ) { System.} } 交通大學資訊工程學系 蔡文能 第99頁 .println("Circle.println("Circle.out.

draw( ) ").draw( )").out.println("Square.println("Triangle. } void erase( ) {System.out.erase( )").println("Triangle. } void erase( ) {System.erase( )").} } 交通大學資訊工程學系 蔡文能 第100頁 .println("Square.out.Java OOP-class Upcasting and Polymorphism class Square extends Shape { void draw( ) { System.}} (3/4) class Triangle extends Shape { void draw( ) { System.out.

i++) s[i] = randShape(). i < s.Java OOP-class Upcasting and Polymorphism public class Shapes { public static Shape randShape() { switch((int) (Math. } } 交通大學資訊工程學系 蔡文能 (4/4) 第101頁 . i < s.random()*3)) { case 0: return new Circle(). //Make polymorphism method calls: for (int i = 0. case 1: return new Square().draw(). default : return new Circle(). i++) s[i]. for (int i = 0. case 2: return new Triangle().} } public static void main(String[] args) { Shape[] s = new Shape[9].length.length.

class Line: public Shape{ public: void draw( ) { cout << "draw a line\n".tw #include <iostream.CopyWrong by tsaiwn@csie.nctu. class Circle: public Shape{ public: void draw( ) { cout << "here is a circle\n".h> class Shape{ public: virtual // 把這列去掉再 run 看看 void draw( ) { cout << "drawing\n".edu. } }. 交通大學資訊工程學系 蔡文能 第102頁 .cpp -. } }.Java OOP-class Polymorphism in C++ (1/2) // polymo. } }.

} } 交通大學資訊工程學系 蔡文能 第103頁 . fig[1] = new Circle(). ppp -> draw(). for(int k=0. k++){ fig[k] -> draw(). ppp -> draw(). cout << "======" << endl. k<5.Java OOP-class Polymorphism in C++ (2/2) int main(){ Circle * ppp. Shape * fig[9]. // error ppp = (Circle *)new Shape(). fig[3] = new Line(). ppp = new Circle(). ppp = (Circle *)new Line(). ppp -> draw(). fig[0] = new Line(). fig[4] = new Circle(). fig[2] = new Circle(). // ppp = new Shape().

Class 謝謝捧場 http://www. Object.Java OOP-class Java: OOP.tw/~tsaiwn/course/java/ 蔡文能 交通大學資訊工程學系 蔡文能 第104頁 .csie.edu.nctu.

20  [  .5  3.  8/ 897.

¡ .

.

470( .  445  8.

 < q #' .

8 .883  .9.=L= 2?=II $97:.

:/048970.. 3.88$9:/039.2  .

.

9$9:/039  438/ < 392. n 897:.3   FHEL=JA $9:/039  8/.

.

4250 ...088349.40/ ..4:9 8/03/.

.

.4250 709:73  <  [ q $ .

=L= 2?=II $97:.8 .9.883  .

2  .88$9:/039. 3..:/048970.

.

57..90 438/ 5:-.84:2-07  709:738/< 809/ 43 8/< < 392.3   $9:/039   809/  .

.

   5:-.943809/  . 1:3.4:9 84:2-07  03/.

.

  709:73  <  [ q $ .

9 43897:.88 -0.=L= 2?=II .947.

88$9:/039..  3.:/048970.2  .

.

90 438/ 5:-.3   $9:/039 2 3 $9:/039  .84:2-07  709:738/< 809/ 43 8/< < 392..57.

.

43897:.:9.7747  809/   709:73  <  [ q  /01.947   $ .947  $9:/039      /01.43897:.:9.

9 43897:.=L= 2?=II .947.88 -0.

:/048970.  3.88$9:/039.2  ..

.

90 438/ 5:-.43897:.57..947 < 392.84:2-07  709:738/< 809/ 43 8/< $9:/039 43 8/< 5 .3   $9:/039   $9:/039.

.

:9.7747  /01.43897:.947 $9:/039  .

.

 34    809/   1 s  709:73  $9:/039     <  [ q $! .

9 43897:.88 -0.=L= 2?=II .947.

.88$9:/039.2  .  3.:/048970.

.

90 438/ 5:-.84:2-07  709:738/< 809/ 43 8/< $9:/039 43 8/< < 392.57..3   $9:/039   .

.

   809/   709:73  < $9:/039  s  01.:9 $"  [ q .

9 43897:.947.88 -0.=L= 2?=II .

2  ..  3.88$9:/039.:/048970.

.

3< < 392.4:9.84:2-07  709:738/< 809/ 43 8/< $9:/039 43 8/.3   $9:/039   .90 438/ 5:-..57..4:90003< $9:/039  8/ .

.

947 $#  [ q .43897:.   809/   $9:/039  709:73  s  < 5 .

0 25020398 .888.3..9433079.9 $.3 -0.880830791742.8808 !74507908 $302502039.450 3098/0  [ q $$ .3.-4:9...0 0903/8 %030790/...0/ 8:507.03079.. .88 :95039071..=L= 2?=II 470.

450  [ q $% .=L= 2?=II $.

9.98 389..9 %030 4507....90820247147.8808..930#0.=L= 2?=II %010..3070..3 -0.9.70.9.73..93.84..9 3.908904-0.9  [ q $& .4.304-0.08.30    %030 4507.39.98 #0.3070.8/.902039 70.947709:738.930#0.9.9 -0.947 %030 4507.947.9.9.93 -0.90/4-0.9 %030 4507.94739.9438.0949030.550.30    19079889.9 #0. .90304-0.9 70.#0.94.089 30#0..9 .3070.43897:..3 -0..9508 0.943  70.7.3-0:80/.30  0..947706:708.947.30 4-0.9 70107894.7.3/39071.430 #0.9/0.70.7.9.70.3/90.041.9.7:2039.9438/4349.43897:..3 -0.7010703.3.

..943  39.#0.9 43897:.30 .9.30 !4395 39 39 5:-.88/408349/0130.574.9478.7:20398 8..88 ...3/.30 39 39 5:-./08.34 .20.#0.39.43897:.203.=L= 2?=II %010.3070.43897:.9.9.3.#0.9.9 70.034709:73 950 5:-..30 !4395 5:-.947  [ q $' .43897:.0/90/01.041.9478 ..7:2039 .9..43897:.0908..930#0.9.7:2039.3.947 .947.9.3 -0.0834.30    #0.30 30!439    .43897:.:9.34 .890..#0.930#0.9.947 1.0/.3 -0.250 #0.3070.

30 30#0.98 #010703.0    39.70.041.9.9 09 70.70.30   . 1#0.0 2094/.9 8'.9#010703.3.0 .3070.9.9 .20 .9 8094/8 4-0.-08 4-0.7:203989  ..3 -0.3 -0.0 2094/.088 &83 -0.9.=L= 2?=II %010.7.9 /9 .9#010703.70.9 24. 1#0..9#010703.7.3.250 70.20  47 4-0.250 39.3 -0.-0 .   [ q % .

=L= 2?=II %010.08949.4 57479970.7-..0.9  %0.706:0891742.0.94-0.041.40..7 8005.040.17008.947 %0.= 28147 .3:5 0.40.98 34-0.7-.0.9477:383.20//0.0/ 570.7-.9.0398202470...947 :942./ 0390889027:384:94120247 37085438094.2  0390889028/0  [ q % .40.33&5&3:80/ -0.70342470 7010703.5747.9 0.7-..3 -0.8 .34-0.9 13497010703.980-0147.943039070.

80 7084:7.425.30 5:-.9.34-0.3..!439473   57490.13.480 9 !74-02.90/ .981789 %013.943147 202472.202-074190 -0.'2502039.0 2094/8.4/13.943 0317003...0.947 8:.9 9088902.02039.10 4-0..90/.439744190.0 2094/94700.83.0 4733: 8:507 13.0  < < q 9748%74.9 .9.88#0.=L= 2?=II 3..40.7-..07.7447.9 .03.9 031700/ 300/94.-0  [ % .0 50078 $.09039073.703 9:3/0790.08 9.250 5:-..88 25020393.

077/3 .250147 .=L= 2?=II .

 .883 ..  8:507    98 ..9    < < $:-. < .4//7.. <  447!439.4//7.90447.90/39  !439 39 39 98 98 < ..  $8902 4:9 57393 !439.9        .8854390903/8 !439 57.88!439 57490. 5439 39 39 447.  $8902 4:9 57393 <  [ q %! ..

250147 .=L= 2?=II .077/3 .

88!43955 5:-.5 5 /7.4/2.  5. .5 /7.  .89.  .3  !439530!439    5439...9.5305439   #0/  5 /7.

.

 475439 8/7.. < <  LAHHE@EC LAH=@EC  [ q %" ..!439 8/7.

7:20398 %04.20 709:73950 ./3 094/ 8. 14.077/0 ./3 849.4..074.88.3/5.077/32094/2:89...70/1107039...20907 89.3/9504190 .204.3 8.88 =L=  FAH=JHLAH=@EC  [ q %# .203..8902094/94.4//7.9.20 1:3.074.077/08 8:-.20 ..#03/0707 .2094/3988:507./0/ 2094/8.074.7. 39    < .0908.4//7.4//7.9433. $9738    < .92:9502094/8.8:5547982094/3.882.70908.90/ -903:2-07.20 .203.91    < < .=L= 2?=II .

..9.9..8808.88 80.47.9.02304947'0.9.9047/ 5:-.92094/834925020390/390.70/ %0 -4/41902094/890325020390/38:-.9 047/ W -897...88 43/0...9.....3349-0389.-897. . 4947'0...=L= 2?=II -897.8808......-897.70..90/$49014438 0.-897.70/ 3.-897.884947'0.88083. W -897.88 3....0 < W 3.90/:8390.3097.-897.0.90/9.70/0.39.92094/8..-897.-897.07.3.92094/ 8/0.

.

  .

.

    .

.

  [ q .

|  %$ .

-897.=L= 2?=II -897.90/4:-08500/ 2.884947'0.0.3...0 57.70/-:9/4349.92094/8 W -897..3..439..250 904947'0.9 .%4.$500/<..3 2502039.882.9 2094/.4/...943 W 470...8   5:-.  8500/2.0.70/0.-897...$500/ .92094/8..

.

.9 .-897..    5:-.4/.8  .

.

        .

  .

90.. < W $44947'0.9  [ q %% .0.3 %-0389.39..3349-0:80/94.34-0.90/ 0 .70.

=L= 2?=II .9 .25041-897..8808 .

-897..250 .  ...9 -0.88$9..94  .-897.9545  < 5:-. .0903/8$9..4/5:8 -0..$9.8877.  ..-897..9 ..9.

.

..4/5:8 -0..700028(.94 0028945 (4< -0.8830/$9./0.0903/8$9.3/945 ..9545 709:730028 945(< < .  .

.

4/5:8 -0.94  < -0.9545  < <  [ q %& .70 ../0.

25041-897..=L= 2?=II .9 .8808 .

 .

.

9.399089$9..3490710 89.. $9.5:-.8  8 5:8  8 5:8   48 545 48 545  .

.

83077.14 4 < 77.  9089$9... ...$9.$9.0.8   [ q %' ..

9.3/89.-897.809412094/89.0 80..3/13.882:892502039 W 339071... 5:-.90%... W 2094/8.....70/.813..-897./4:-0.:...88 93493-:9.39071..//0/94.0 .9 2094/8 .9.0 5:-.=L= 2?=II 39071.70./.98. ..9 W 39071.8:-.0 25479%.70.....9 25.   <  [ q & .889.34907.8841 .10/8 .88  25020398 W %4/0..70..0 ...010/8 -:99010/82:89-0 /0.84.398 W 339071..4389.9.3-0.08 01308.339071..3.3/89.

.=L= 2?=II .08 .2504139071.

.4/5:8 -0.8877.. ..94  -0..9545  < 5:-..25020398$9.  .$9.. 39071.0 $9.

.

/0..3/945 .25020398$9.94 0028945 (4< -0..4/5:8 -0.8830/$9...  .9545 709:730028 945(< < .700028(.

.

4/5:8 -0.9545  < <  [ q & ..70 .94  < -0./0.

08 ..2504139071.=L= 2?=II .

 .

.

5:-.3490710 89..399089$9.8  8 5:8  8 5:8   48 545 48 545  ..9. $9.

.

.8   [ q & .14 4 < 77.83077..$9.$9.0....  9089$9. .

.88 .9 .88 8.07.92094/8..88.3/39071..-897.88..-897..439.3380.880/ W 339071...-897..0 .0 .3/..0-09003-897.439.92094/857010/990047/ .9..343-025020390/  [ q &! .-897.92094/8 .....90/-:9.3843..-897.9 W 339071.0 W 3.=L= 2?=II 110703.....-897..-897.3-00903/0/ 8:-.4389.9  W 3....3349-0389..398  ..39.92094/834957010/ 990047/ .9.-897.

4/5:8 .1:3.79:. . .=L= 2?=II 4 0.79:..8808 &80.4/ 545 &..08 47-897..4/ 4 & . .9438 .9.79:.8939071..88 $9.

.

& <  &   .

.

79:. .¡   .

.

1:3.79:. 1:3.9435:70.79:. &   .943 .

.

/0838 014790/083841 ... .. Ÿ î .9.79:.709039073.

74$419  [ q &" .  .

8877...250147 .  .=L= 2?=II .$9..$9.

.

9545 709:730028 945(< < .4/5:8 -0.3/945 .$9..700028(.8830/$9.  ..94 0028945 (4< -0./0...

.

8  8 5:8  8 5:8   48 545 48 545  .4/5:8 -0. $9.70 ./0.94  < -0..9545  < < 3490710 399089$9...

.

.0..  9089$9.. .8   [ q &# .$9.83077.14 4 < 77..$9..

883.0 07.=L= 2?=II !..7.08.....3/-7.8843...30. 4  ..947897:..0 .. 88 25479.90/3/70..2085./.7 7..9:70  0 5.8432:89-07010.

31.9 988. 88 43 ...

2  ..05943 $973 .< 01.8250 70897../ ..943  [ q &$ .2  :95:9$970..80/4-0.947 9$09 #005  ..943 0-:3 4.08 -7.7   ....:2039.. 9448 425. .98 .:95.89. 309 09473 8:55479147$4. . 4 35:9$970.3 -0.9 %70..90/3/43! ...-0 '0....9 -897.93/49449 /01308.09 &# -. :9 .

88390 =L=  [ q CH=FDE?I4A?J=CA &% ..0 %03.88390 ....204190 5.. %03.=L= 2?=II ...0870..23.0870.204190 5.!. .

..=L= 2?=II .0884/1078 34047/ .88.

.0..3494.088 8..02094/825020390/33.88..08 .43430...077//03 3..98349507889039  [ q && .4/0 83..90/8:-.5.-897.9.088 8.389.9.883.088 /11070391742  0 5./ 97.7430//08.20.0.20.-0 5:-...7-0/3%70....9.9..45147.3.9019:325020390/ 13.9..8 89.20.38039/..088 8...8 57490.8 57..47/.0.90.

88 $50.107 57.0   .90 57490..90/ 5:-.0 47/                 ¡ s : 8   [ q &' ...0889402-07841.88 !..=L= 2?=II 425..88 $:-...78438 439743.. 5.

-0 0.88.4-.0334389..3.9.. 39   39.08 &8:.:80/.3/.3.4514790.9.389..9. 89.8... 43430.07.08 .=L= 2?=II $9.88%089$9.7.0 709:73    .

9.< 89.39500    .9.39  5J=JE?L=HE=>A  89.

.

07747 < 5J=JE?>? 89.39500  89. < .9.9.

.

89.9.098 .78  %089$9..9830%089$9../430034.  39..3 $973(.07./3.0  5J=JE?AJD@ < < 5J=JE? AJD@  [ q ' ..9.4/2.88 5:-.9.

039.2094/82094/89.-08..08 13..   -..=L= 2?=II 3.3349.794.19079..30.-09..398349075747..7.7.39-..7082.-08 %0.8-003 39..0/.313.3:.:041.8-003/0.13.9.0/8 .7.313.313.70/-:93490939. 13....9.4.  3.7.44770/447 70/ 13.-.3349-04.077//03 !70.223 .039817424. 3..-0..077/3 4147%9445920   [ q ' ..0/  $:.4389..

202-07  [ q ' ..38039.4.984:/349-0807.7.38039 :80/34-0.425071742 50714723.0/ .03990.943942.-089.34592.9807.8 '4.7202-07 .=L= 2?=II %7.079.943843..90 97.90 :80/94570.

...88.88 8202-078 0.9.483.88039030890/..42543039  30890/..43909419803..483.8893...088038043390.88  470.889.57..88 2.8:3290/.90  :890.3.2094/9..202-0741.:.90  [ q '! .4390941..850.250 .88 30890/.=L= 2?=II 0890/.7909..8.08857.34907. 5.:78472.888.34907..79....88 ?=II-?IEC+=II  ?=II)AIJA@+=II    0130..088038043390..088949803..03147 57.00 9.98.909.

..3/2094/8  0..8/70.-08..33307.89.0/.994389.9..3.9.3.3.9.888.7.88  33307..9.88  89.3389.0419803...90/9..0 9..7.884..-0847 2094/8/0130/39803..202-0789801  [ q '" .88 ?=II-?IEC+=II  IJ=JE? ?=II)5J=JE?AIJA@+=II   ?=II1AH+=II IJ=JE?EIMHC EJDEIEAH?=II   89.9 8389.0..88.3389.888.88 34389.3349/0130 .3.9..334970107/70.88...30890/.=L= 2?=II %508410890/.888.483..884.888.389.30890/..9.3/ .:80..94-0.088949.90/9..0/.33307.0.483.30890/.30890/.

0413307.3389.90909072830890/...94385-09003 389..7.8/70.483..3.483 389.9.88.08419094.4397.3/2094/8419803.89 9090723307..88.08894389.88 9..9.3.3...3.70.887010.=L= 2?=II 0890/.989070..887010..88 %0907230890/.8808  3389.0  ?=II-?IEC+=II  ?=II1AH+=II     [ q '# .30894393.0.9890839.8 3307 %405/1107039.-08.8808  3.3.94385-09003 94.041 3.3/3307..

:9 3:207.5947 &83.02039..5907 25479. :9 4$:..33307..943 25479.250/..3/.=L= 2?=II .88942502039.05943 FK>E??=II5J=?  FHEL=JA=L=KJE8A?JH EJAI ?@ABH5J=?IAJD@I=@?IJHK?JHIJIDM FK>E?-KAH=JEAKAH=JH HAJKHAM5J=?-K  ?=II5J=?-K EFAAJI-KAH=JE EJ?KHHAJ1JAEJAIIEA  FK>E?>A=D=IHA-AAJI HAJKH?KHHAJ1JA  FK>E?>A?JANJ-AAJ EBD=IHA-AAJI JDHMAM5K?D-AAJ-N?AFJE AIA HAJKHEJAIAAAJ)J?KHHAJ1JA     [ q '$ .

250 #079090570...33307.3/0.239  .70..8894:93.=L= 2?=II 34324:8.4:88/0 FK>E??=II5J=? FHEL=JA8A?JHEJAI ?@ABH5J=?IAJD@I=@?IJHK?JHIJIDM FK>E?-KAH=JEAKAH=JH HAJKHAM-KAH=JE EJ?KHHAJ1JAEJAIIEA  FK>E?>A=D=IHA-AAJI HAJKH?KHHAJ1JA  FK>E?>A?JANJ-AAJ EBD=IHA-AAJI JDHMAM5K?D-AAJ-N?AFJE AIA HAJKHEJAIAAAJ)J?KHHAJ1JA      [ q '% .88 4:.

893..3/!4247582 .=L= 2?=II &5.

3990-..939.09498-.97010703.. W &5...893 -0.3.88.3/970.70/7..80.0.990945  [ q '& . 7010703.3079.34-0.8.809508.3.893%.0/:5.097008.:804190 .

 07.=L= 2?=II &5.80 7.50 /7. 07.3/!4247582 .80  < < $.  < .0 /7..50 .88$.893.4/07..80 .4//7.

0/54247582 .0/8. 07..    < .887.509.50 .  W !42475823..80  $8902 4:9 57393 7.80 '' .80   < <  [ q $6:.   $8902 4:9 57393 7. 07..9504190 4-0.9:.80 %7..9/09072308902094/ 94-0..00903/8$.70 /7.0 /7..4//7.990. 90573.0 07.4/07.30 /7.

4//7.70 /7.   $8902 4:9 57393 $6:.88$6:.=L= 2?=II &5.80  $8902 4:9 57393 $6:.    < ..50 .700903/8$.80   << .893.4/07.3/!4247582 ..70 07.

4/07.80   $8902 4:9 57393 %7.80   < <  [ q  .    < .  .4//7.88%7.50 .30 /7.30 07.   $8902 4:9 57393 %7.300903/8$..

.893.=L= 2?=II &5.508 5:-.50(830$.9.3/!4247582 5:-...30  /01.50  89..4/2.80709:7330%7.80709:7330$6:.80 709:73307. 39  .9.70  .0 < < 5:-.89.9 7.$.3/42   ..3/$.507.78  $.3/$.:9709:73307.89..50  .88$.0  .3 $973(.50( 147 39 8 039 8(7..

.

0542475822094/.  < <  [ q ...8 147 39 8 039 8( /7.

   .

=L= 2?=II !42475823  .

 .

.

.5424 .88$.3.2  . .55 45743-98.9: 0/: 9 3.79:.:/048970.50 5:-..80 3.

.

  .88305:-.4:9/7.303< < .  .4:90708.$.7.50 5:-.4:9/7.$...887..4//7. .   7:3 .05:-.33< < .4//7.4//7..50 5:-. .  .03< <  [ q  .

50 1( .3  7.0 555 $.=L= 2?=II !42475823 392.

.

50 .55530$.

.

0  1(307.4:903/ 1 (3030  1(307.0 555 /7.0  1(3030 1(307.  < <  [ q  .  555 7.0 3030 555 /7.0 30$.07747 555 7.0  147 39   1( /7.50  555 /7.  .  555307.

 ! .

=L= 2?=II ..9 .88 X 995.. !  -0.

.

9: 0/: 9.80 3. .

=98.3.

.4:780.

.

q  [ q " .