Concepts of Object-Oriented Programming. 19 October 2016 OSU CSE 1

Size: px
Start display at page:

Download "Concepts of Object-Oriented Programming. 19 October 2016 OSU CSE 1"

Transcription

1 Concepts of Object-Oriented Programming 19 October 2016 OSU CSE 1

2 Recall... Standard implements extends NaturalNumber- Kernel extends NaturalNumber implements NaturalNumber1L NaturalNumber2 19 October 2016 OSU CSE 2

3 The Implements Relation The implements relation may hold between a class and an interface If C implements I then class C contains code for the behavior specified in interface I This means C has method bodies for instance methods whose contracts are specified in I The code for C looks like this: class C implements I { // bodies for methods specified in I } 19 October 2016 OSU CSE 3

4 The Implements Relation The implements The relation implements may relation hold between allows a class and an interface you to separate contracts from their implementations a best If C implements practice I then for class component C contains design. code for the behavior specified in interface I This means C has method bodies for instance methods whose contracts are specified in I The code for C looks like this: class C implements I { // bodies for methods specified in I } 19 October 2016 OSU CSE 4

5 The Implements Relation The Java compiler checks that C The implements relation may hold between contains bodies for the methods in a class and an interface I, but does not check that those If C implements Ibodies then correctly class implement C contains the method contracts! code for the behavior specified in interface I This means C has method bodies for instance methods whose contracts are specified in I The code for C looks like this: class C implements I { // bodies for methods specified in I } 19 October 2016 OSU CSE 5

6 The Extends Relation The extends relation may hold between: Two interfaces (as on the earlier slide), or Two classes In either case, if B extends A then B inherits all the methods of A This means B implicitly starts out with all the method contracts (for an interface) or all the method bodies (for a class) that A has B can then add more method contracts (for an interface) or method bodies (for a class) 19 October 2016 OSU CSE 6

7 Caveats About Java Interfaces If B extends A then B inherits all the methods of A Interfaces cannot have constructors So there is no good place to write separate contracts for the constructors of classes that implement an interface Interfaces cannot have static method contracts without also providing corresponding method bodies So there is no good place to write separate contracts for public static methods of classes that implement an interface 19 October 2016 OSU CSE 7

8 Caveats About Java Classes If B extends A then B inherits all the methods of A Constructors are not inherited So in the situation above, the class B must include bodies for any constructors that are expected, even if they would be identical to those of A The bodies of the constructors in B generally would simply invoke the constructors of A, which is done using the special notation super( ) Static methods are inherited 19 October 2016 OSU CSE 8

9 Implements May Be Inferred I1 extends I2 implements C3 extends C4 19 October 2016 OSU CSE 9

10 Implements May Be Inferred I1 I2 extends implements implements C3 C4 extends We may infer in this case that C3 implements I1. 19 October 2016 OSU CSE 10

11 Implements May Be Inferred I1 I2 extends We may also infer in this case that C4 implements I2. implements C3 extends implements C4 19 October 2016 OSU CSE 11

12 Interface Extension If I1 and I2 are interfaces and I2 extends I1, then the code for I2 looks like this: interface I2 extends I1 { // contracts for methods added in I2 } I1 I2 extends 19 October 2016 OSU CSE 12

13 Interface Extension If I1 and I2 are interfaces and I2 extends I1, then the code for I2 looks like this: interface I2 extends I1 { // contracts for methods added in I2 } I1 I2 extends Remember, for interfaces all such methods are instance methods! 19 October 2016 OSU CSE 13

14 Interface Extension If I1 and I2 are interfaces and I2 extends I1, then the code for I2 looks like this: interface I2 extends I1 { // contracts for methods added in I2 } I1 I2 extends Other terminology for this situation: I2 is a subinterface of I1 I2 is a derived interface of I1 I2 is a child interface of I1 19 October 2016 OSU CSE 14

15 Interface Extension If I1 and I2 are interfaces and I2 extends I1, then the code for I2 looks like this: interface I2 extends I1 { // contracts for methods added in I2 } I1 I2 extends Other terminology for this situation: I1 is a superinterface of I2 I1 is a base interface of I2 I1 is a parent interface of I2 19 October 2016 OSU CSE 15

16 Example: Interface Extension Standard extends NaturalNumber- Kernel clear newinstance transferfrom clear newinstance transferfrom + multiplyby10 divideby10 iszero = multiplyby10 divideby10 iszero 19 October 2016 OSU CSE 16

17 Example: Interface Extension clear NaturalNumberKernel actually Standard newinstance has all these methods, even though transferfrom their contracts are in two separate interfaces. extends + NaturalNumber- Kernel clear newinstance transferfrom multiplyby10 divideby10 iszero = multiplyby10 divideby10 iszero 19 October 2016 OSU CSE 17

18 Example: Interface Extension clear The extends relation for interfaces Standard newinstance allows you to separate contracts into transferfrom smaller chunks arguably a best practice for extends component design. + NaturalNumber- Kernel clear newinstance transferfrom multiplyby10 divideby10 iszero = multiplyby10 divideby10 iszero 19 October 2016 OSU CSE 18

19 Class Extension For classes, extension can serve two different purposes: To add method bodies that are not already in the class being extended (similar to the use of extension for interfaces) To override methods that are already implemented in the class being extended, by providing new method bodies for them 19 October 2016 OSU CSE 19

20 Class Extension When pronounced, this may sound like overwrite, but that is not a correct interpretation! For classes, extension can serve two different purposes: To add method bodies that are not already in the class being extended (similar to the use of extension for interfaces) To override methods that are already implemented in the class being extended, by providing new method bodies for them 19 October 2016 OSU CSE 20

21 Class Extension For classes, extension For now, we can are concerned serve two only with different purposes: this use of class extension. To add method bodies that are not already in the class being extended (similar to the use of extension for interfaces) To override methods that are already implemented in the class being extended, by providing new method bodies for them 19 October 2016 OSU CSE 21

22 Class Extension Important note: Overriding a method is different from overloading a method! A method (name) is overloaded when two or more methods have the same name, in which For classes, extension can serve two different purposes: case the methods must differ in the number and/or types of their formal parameters (which To add method the compiler bodies uses that to disambiguate are not already them). in the class being extended (similar to the use of extension for interfaces) To override methods that are already implemented in the class being extended, by providing new method bodies for them 19 October 2016 OSU CSE 22

23 Class Extension If C1 and C2 are classes and C2 extends C1, then the code for C2 looks like this: class C2 extends C1 { // code for methods added or // overridden in C2 } C1 C2 extends 19 October 2016 OSU CSE 23

24 Class Extension If C1 and C2 are classes and C2 extends C1, then the code for C2 looks like this: class C2 extends C1 { // code for methods added or // overridden in C2 } C1 C2 extends Remember, for classes these may be either static methods or instance methods. 19 October 2016 OSU CSE 24

25 Class Extension If C1 and C2 are classes and C2 extends C1, then the code for C2 looks like this: class C2 extends C1 { // code for methods added or // overridden in C2 } C1 C2 extends Other terminology for this situation: C2 is a subclass of C1 C2 is a derived class of C1 C2 is a child class of C1 19 October 2016 OSU CSE 25

26 Class Extension If C1 and C2 are classes and C2 extends C1, then the code for C2 looks like this: class C2 extends C1 { // code for methods added or // overridden in C2 } C1 C2 extends Other terminology for this situation: C1 is a superclass of C2 C1 is a base class of C2 C1 is a parent class of C2 19 October 2016 OSU CSE 26

27 Example: Overriding a Method NaturalNumber2 extends NaturalNumber2- Override... power... power 19 October 2016 OSU CSE 27

28 Example: Overriding a Method NaturalNumber2 extends NaturalNumber2- Override... power... power There is a method body for power in NaturalNumber October 2016 OSU CSE 28

29 Example: Overriding a Method NaturalNumber2 extends NaturalNumber2- Override... power... power... and there is another method body for power in NaturalNumber2Override. 19 October 2016 OSU CSE 29

30 @Override Annotation When writing the code for the body of either a method whose contract is from an interface being implemented, or that overrides a method in a class being extended you preface the method body with annotation 19 October 2016 OSU CSE 30

31 public void power(int p) {... } 19 October 2016 OSU CSE 31

32 Which Method Body Is Used? NaturalNumber2 extends NaturalNumber2- Override... power...? power This raises the question: Which method body for power is used when power is called in a client program? 19 October 2016 OSU CSE 32

33 Interface as Declared Type When a variable is declared using the name of an interface as its type, e.g.: NaturalNumber k = new NaturalNumber2(); then its declared type (or static type) is said to be an interface type 19 October 2016 OSU CSE 33

34 Interface as Declared Type When a variable is declared using the name of an interface as its type, e.g.: NaturalNumber k = new NaturalNumber2(); then its declared type (or static type) is said to be an interface type Here, the declared type of k is NaturalNumber. 19 October 2016 OSU CSE 34

35 Interface as Declared Type When a variable is declared using the name of an interface as its type, e.g.: NaturalNumber k = new NaturalNumber2(); then its declared type (or static type) is said to be an interface type Best practice is for variables to be declared using an interface type, as shown here. 19 October 2016 OSU CSE 35

36 Class as Declared Type When a variable is declared using the name of a class as its type, e.g.: NaturalNumber2 k = new NaturalNumber2(); then its declared type (or static type) is said to be a class type 19 October 2016 OSU CSE 36

37 Class as Declared Type When a variable is declared using the name of a class as its type, e.g.: NaturalNumber2 k = new NaturalNumber2(); then its declared type (or static type) is said to be a class type Here, the declared type of k is NaturalNumber2. 19 October 2016 OSU CSE 37

38 Class as Declared Type When a variable is declared using the name of a class as its type, e.g.: NaturalNumber2 k = new NaturalNumber2(); then its declared type (or static type) is said to be a class type Best practice is for variables to be declared using an interface type, but Java will let you use a class type, as shown here. 19 October 2016 OSU CSE 38

39 Object Type When a variable is instantiated (an object for it to reference is constructed), e.g.: NaturalNumber k = new NaturalNumber2(); then its object type (or dynamic type) is the class type from which the constructor comes 19 October 2016 OSU CSE 39

40 Object Type When a variable is instantiated NaturalNumber2. (an object for it to reference is constructed), e.g.: NaturalNumber k = new NaturalNumber2(); Here, the object type of k is then its object type (or dynamic type) is the class type from which the constructor comes 19 October 2016 OSU CSE 40

41 Declared/Object Type Rule Suppose we follow best practices, and: The declared type of some variable is the interface type I The object type of that variable is the class type C Then the relation C implements I must hold Java enforces this rule! 19 October 2016 OSU CSE 41

42 Polymorphism Finally, back to overriding... Java and other object-oriented languages decide which method body to use for any call to an instance method based on the object type of the receiver This type, because it is the class of the constructor, is always a class type This behavior for calling methods is known as polymorphism: having many forms 19 October 2016 OSU CSE 42

43 Example of Polymorphism NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override();... k.power(2); n.power(2); October 2016 OSU CSE 43

44 Example of Polymorphism NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override();... k.power(2); n.power(2);... This call of power uses the method body for power from NaturalNumber2 (which is the object type of k). 19 October 2016 OSU CSE 44

45 Example of Polymorphism NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override();... k.power(2); n.power(2);... This call of power uses the method body for power from NaturalNumber2Override (which is the object type of n). 19 October 2016 OSU CSE 45

46 Example of Polymorphism NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override();... k.power(2); n.power(2);... Note that the declared type of both k and n is NaturalNumber, and it does not determine which method body is used. 19 October 2016 OSU CSE 46

47 Another Example NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override(); NaturalNumber j = k;... j.power(2); October 2016 OSU CSE 47

48 Another Example NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override(); NaturalNumber j = k;... j.power(2);... This call of power uses the method body for power from NaturalNumber2 (which is the object type of j) October 2016 OSU CSE 48

49 Another Example NaturalNumber k = new NaturalNumber2(); NaturalNumber n = new NaturalNumber2Override(); NaturalNumber j = n;... j.power(2); but this call of power uses the method body for power from NaturalNumber2Override (which is the object type of j). 19 October 2016 OSU CSE 49

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship. CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

CIS 190: C/C++ Programming. Polymorphism

CIS 190: C/C++ Programming. Polymorphism CIS 190: C/C++ Programming Polymorphism Outline Review of Inheritance Polymorphism Car Example Virtual Functions Virtual Function Types Virtual Table Pointers Virtual Constructors/Destructors Review of

More information

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism Polymorphism 1 Agenda What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism 2 What is & Why Polymorphism? 3 What is Polymorphism? Generally, polymorphism refers

More information

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

Description of Class Mutation Mutation Operators for Java

Description of Class Mutation Mutation Operators for Java Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University

More information

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT

More information

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

PHP Object Oriented Classes and objects

PHP Object Oriented Classes and objects Web Development II Department of Software and Computing Systems PHP Object Oriented Classes and objects Sergio Luján Mora Jaume Aragonés Ferrero Department of Software and Computing Systems DLSI - Universidad

More information

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts

More information

Inheritance, overloading and overriding

Inheritance, overloading and overriding Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards Course Title: TeenCoder: Java Programming Course ISBN: 978 0 9887070 2 3 Course Year: 2015 Note: Citation(s) listed may represent

More information

Java Programming Language

Java Programming Language Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and

More information

Checking Access to Protected Members in the Java Virtual Machine

Checking Access to Protected Members in the Java Virtual Machine Checking Access to Protected Members in the Java Virtual Machine Alessandro Coglio Kestrel Institute 3260 Hillview Avenue, Palo Alto, CA 94304, USA Ph. +1-650-493-6871 Fax +1-650-424-1807 http://www.kestrel.edu/

More information

Chapter 1 Fundamentals of Java Programming

Chapter 1 Fundamentals of Java Programming Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

Chapter 13 - Inheritance

Chapter 13 - Inheritance Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

More information

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword. http://www.tutorialspoint.com/java/java_inheritance.htm JAVA - INHERITANCE Copyright tutorialspoint.com Inheritance can be defined as the process where one class acquires the properties methodsandfields

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

CS193j, Stanford Handout #10 OOP 3

CS193j, Stanford Handout #10 OOP 3 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples

More information

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction Standard 2: Technology and Society Interaction Technology and Ethics Analyze legal technology issues and formulate solutions and strategies that foster responsible technology usage. 1. Practice responsible

More information

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example. Industrial Programming Systems Programming & Scripting Lecture 12: C# Revision 3 Pillars of Object-oriented Programming Encapsulation: each class should be selfcontained to localise changes. Realised through

More information

DIPLOMADO DE JAVA - OCA

DIPLOMADO DE JAVA - OCA DIPLOMADO DE JAVA - OCA TABLA DE CONTENIDO INTRODUCCION... 3 ESTRUCTURA DEL DIPLOMADO... 4 Nivel I:... 4 Fundamentals of the Java Programming Language Java SE 7... 4 Introducing the Java Technology...

More information

Programming Languages Featherweight Java David Walker

Programming Languages Featherweight Java David Walker Programming Languages Featherweight Java David Walker Overview Featherweight Java (FJ), a minimal Javalike language. Models inheritance and subtyping. Immutable objects: no mutation of fields. Trivialized

More information

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java Génie Logiciel et Gestion de Projets Object-Oriented Programming An introduction to Java 1 Roadmap History of Abstraction Mechanisms Learning an OOPL Classes, Methods and Messages Inheritance Polymorphism

More information

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance Introduction to C++ January 19, 2011 Massachusetts Institute of Technology 6.096 Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance We ve already seen how to define composite datatypes

More information

CSE 308. Coding Conventions. Reference

CSE 308. Coding Conventions. Reference CSE 308 Coding Conventions Reference Java Coding Conventions googlestyleguide.googlecode.com/svn/trunk/javaguide.html Java Naming Conventions www.ibm.com/developerworks/library/ws-tipnamingconv.html 2

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java Génie Logiciel et Gestion de Projets Object-Oriented Programming An introduction to Java 1 Roadmap History of Abstraction Mechanisms Learning an OOPL Classes, Methods and Messages Inheritance Polymorphism

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) { Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for

More information

Computing Concepts with Java Essentials

Computing Concepts with Java Essentials 2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann

More information

Object-Oriented Programming: Polymorphism

Object-Oriented Programming: Polymorphism 1 10 Object-Oriented Programming: Polymorphism 10.3 Demonstrating Polymorphic Behavior 10.4 Abstract Classes and Methods 10.5 Case Study: Payroll System Using Polymorphism 10.6 final Methods and Classes

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Formal Engineering for Industrial Software Development

Formal Engineering for Industrial Software Development Shaoying Liu Formal Engineering for Industrial Software Development Using the SOFL Method With 90 Figures and 30 Tables Springer Contents Introduction 1 1.1 Software Life Cycle... 2 1.2 The Problem 4 1.3

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Abstract Class & Java Interface

Abstract Class & Java Interface Abstract Class & Java Interface 1 Agenda What is an Abstract method and an Abstract class? What is Interface? Why Interface? Interface as a Type Interface vs. Class Defining an Interface Implementing an

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Agile Software Development

Agile Software Development Agile Software Development Lecturer: Raman Ramsin Lecture 13 Refactoring Part 3 1 Dealing with Generalization: Pull Up Constructor Body Pull Up Constructor Body You have constructors on subclasses with

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Embedded Software development Process and Tools: Lesson-1

Embedded Software development Process and Tools: Lesson-1 Embedded Software development Process and Tools: Lesson-1 Introduction to Embedded Software Development Process and Tools 1 1. Development Process and Hardware Software 2 Development Process Consists of

More information

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices What is Java? Result of Sun s efforts to remedy bad software engineering practices It is commonly thought of as a way to make Web pages cool. It has evolved into much more. It is fast becoming a computing

More information

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition Java 6 'th edition Concepts INTERNATIONAL STUDENT VERSION CONTENTS PREFACE vii SPECIAL FEATURES xxviii chapter i INTRODUCTION 1 1.1 What Is Programming? 2 J.2 The Anatomy of a Computer 3 1.3 Translating

More information

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)

More information

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Yosemite National Park, California. CSE 114 Computer Science I Inheritance Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice

More information

D06 PROGRAMMING with JAVA

D06 PROGRAMMING with JAVA Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch13 Inheritance PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for accompanying

More information

CS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 25 Multiple Inheritance and Interfaces Dan Grossman 2012 Multiple Inheritance Why not allow class C extends C1,C2,...{...} (and C C1 and C C2)? What everyone

More information

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0 The following applies to all exams: Once exam vouchers are purchased you have up to one year from the date of purchase to use it. Each voucher is valid for one exam and may only be used at an Authorized

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading: 9.1 The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale

More information

ATM Case Study OBJECTIVES. 2005 Pearson Education, Inc. All rights reserved. 2005 Pearson Education, Inc. All rights reserved.

ATM Case Study OBJECTIVES. 2005 Pearson Education, Inc. All rights reserved. 2005 Pearson Education, Inc. All rights reserved. 1 ATM Case Study 2 OBJECTIVES.. 3 2 Requirements 2.9 (Optional) Software Engineering Case Study: Examining the Requirements Document 4 Object-oriented design (OOD) process using UML Chapters 3 to 8, 10

More information

Advanced Data Structures

Advanced Data Structures C++ Advanced Data Structures Chapter 8: Advanced C++ Topics Zhijiang Dong Dept. of Computer Science Middle Tennessee State University Chapter 8: Advanced C++ Topics C++ 1 C++ Syntax of 2 Chapter 8: Advanced

More information

Compile-time type versus run-time type. Consider the parameter to this function:

Compile-time type versus run-time type. Consider the parameter to this function: CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();

More information

Understanding Software Static and Dynamic Aspects

Understanding Software Static and Dynamic Aspects Understanding Software Static and Dynamic Aspects Welf Löwe IPD, Universität Karlsruhe PF 6980, 76128 Karlsruhe Germany loewe@ira.uka.de Andreas Ludwig IPD, Universität Karlsruhe PF 6980, 76128 Karlsruhe

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

Extending Classes with Services

Extending Classes with Services Chapter 2 Extending Classes with Services Chapter Objectives After studying this chapter, you should be able to: Extend an existing class with new commands Explain how a message sent to an object is resolved

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

Instance Creation. Chapter

Instance Creation. Chapter Chapter 5 Instance Creation We've now covered enough material to look more closely at creating instances of a class. The basic instance creation message is new, which returns a new instance of the class.

More information

Classes and Pointers: Some Peculiarities (cont d.)

Classes and Pointers: Some Peculiarities (cont d.) Classes and Pointers: Some Peculiarities (cont d.) Assignment operator Built-in assignment operators for classes with pointer member variables may lead to shallow copying of data FIGURE 3-22 Objects objectone

More information

Multiple Dispatching. Alex Tritthart WS 12/13

Multiple Dispatching. Alex Tritthart WS 12/13 Multiple Dispatching Alex Tritthart WS 12/13 Outline 1 Introduction 2 Dynamic Dispatch Single Dispatch Double Dispatch 3 Multiple Dispatch Example 4 Evaluation 2 / 24 What is it all about? Introduction

More information

5. Advanced Object-Oriented Programming Language-Oriented Programming

5. Advanced Object-Oriented Programming Language-Oriented Programming 5. Advanced Object-Oriented Programming Language-Oriented Programming Prof. Dr. Bernhard Humm Faculty of Computer Science Hochschule Darmstadt University of Applied Sciences 1 Retrospective Functional

More information

Automaton Programming and Inheritance of Automata

Automaton Programming and Inheritance of Automata Declarative Approach to Implementing Automata Classes in Imperative Programming Languages Artyom Astafurov, Anatoly Shalyto (research supervisor), Fac. of Information Technologies and Programming St. Petersburg

More information

UML Class Diagrams (1.8.7) 9/2/2009

UML Class Diagrams (1.8.7) 9/2/2009 8 UML Class Diagrams Java programs usually involve multiple classes, and there can be many dependencies among these classes. To fully understand a multiple class program, it is necessary to understand

More information

Android Application Development Course Program

Android Application Development Course Program Android Application Development Course Program Part I Introduction to Programming 1. Introduction to programming. Compilers, interpreters, virtual machines. Primitive data types, variables, basic operators,

More information

Part 3: GridWorld Classes and Interfaces

Part 3: GridWorld Classes and Interfaces GridWorld Case Study Part 3: GridWorld Classes and Interfaces In our example programs, a grid contains actors that are instances of classes that extend the Actor class. There are two classes that implement

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Kenneth M. Anderson Lecture 20 CSCI 5828: Foundations of Software Engineering OO Design 1 Object-Oriented Design Traditional procedural systems separate data and procedures, and

More information

Lab Manual: Using Rational Rose

Lab Manual: Using Rational Rose Lab Manual: Using Rational Rose 1. Use Case Diagram Creating actors 1. Right-click on the Use Case View package in the browser to make the shortcut menu visible. 2. Select the New:Actor menu option. A

More information

Java SE 7 Programming

Java SE 7 Programming Java SE 7 Programming The second of two courses that cover the Java Standard Edition 7 (Java SE 7) Platform, this course covers the core Application Programming Interfaces (API) you will use to design

More information

In order to understand Perl objects, you first need to understand references in Perl. See perlref for details.

In order to understand Perl objects, you first need to understand references in Perl. See perlref for details. NAME DESCRIPTION perlobj - Perl object reference This document provides a reference for Perl's object orientation features. If you're looking for an introduction to object-oriented programming in Perl,

More information

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities The classroom is set up like a traditional classroom on the left side of the room. This is where I will conduct my

More information

Constructor, Destructor, Accessibility and Virtual Functions

Constructor, Destructor, Accessibility and Virtual Functions Constructor, Destructor, Accessibility and Virtual Functions 182.132 VL Objektorientierte Programmierung Raimund Kirner Mitwirkung an Folienerstellung: Astrit Ademaj Agenda Constructor Destructors this

More information

Java SE 7 Programming

Java SE 7 Programming Oracle University Contact Us: 1.800.529.0165 Java SE 7 Programming Duration: 5 Days What you will learn This Java SE 7 Programming training explores the core Application Programming Interfaces (API) you'll

More information

Java SE 7 Programming

Java SE 7 Programming Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 4108 4709 Java SE 7 Programming Duration: 5 Days What you will learn This Java Programming training covers the core Application Programming

More information

Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming

Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming Written exam in Introductory Programming IT University of Copenhagen, June 11, 2001 English version All materials are permitted during the exam, except computers. The exam questions must be answered in

More information

Unit Testing. and. JUnit

Unit Testing. and. JUnit Unit Testing and JUnit Problem area Code components must be tested! Confirms that your code works Components must be tested t in isolation A functional test can tell you that a bug exists in the implementation

More information

An Internet Course in Software Development with C++ for Engineering Students

An Internet Course in Software Development with C++ for Engineering Students An Internet Course in Software Development with C++ for Engineering Students Yosef Gavriel, Robert Broadwater Department of Electrical and Computer Engineering Virginia Tech Session 3232 Abstract This

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1 A Review of the OOP Polymorphism Concept Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1 Outline Overview Type Casting and Function Ambiguity Virtual Functions,

More information

Version Control Using Subversion. 12 May 2013 OSU CSE 1

Version Control Using Subversion. 12 May 2013 OSU CSE 1 Version Control Using Subversion 12 May 2013 OSU CSE 1 Version Control In team projects, software engineers: Share and extend a common code base (and comply with standards, coding conventions, comment

More information

CEC225 COURSE COMPACT

CEC225 COURSE COMPACT CEC225 COURSE COMPACT Course GEC 225 Applied Computer Programming II(2 Units) Compulsory Course Duration Two hours per week for 15 weeks (30 hours) Lecturer Data Name of the lecturer: Dr. Oyelami Olufemi

More information

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: JAVA OBJECTS JAVA OBJECTS AND CLASSES Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: Polymorphism Inheritance

More information

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB) Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB) Course Number: 4995 Length: 5 Day(s) Certification Exam There are no exams associated with this course. Course Overview

More information

A Simple Security-Aware MOP for Java 119

A Simple Security-Aware MOP for Java 119 A simple security-aware MOP for Java Denis Caromel, Fabrice Huet and Julien Vayssi re INRIA - CNRS - I3S Universit de Nice Sophia-Antipolis First.Last@sophia.inria.fr Abstract. This article investigates

More information

Systematically Refactoring Inheritance to Delegation in JAVA

Systematically Refactoring Inheritance to Delegation in JAVA Systematically Refactoring Inheritance to Delegation in JAVA Hannes Kegel ej-technologies GmbH Claude-Lorrain-Straße 7 D-81543 München hannes.kegel@ej-technologies.com Friedrich Steimann Lehrgebiet Programmiersysteme

More information

An Introduction to Object-Oriented Programming with

An Introduction to Object-Oriented Programming with An Introduction to Object-Oriented Programming with TM Java C. Thomas Wu Naval Postgraduate School Ml McGraw-Hill Boston Burr Ridge, IL Dubuque, IA Madison, WI New York San Francisco St. Louis Bangkok

More information

Advanced OOP Concepts in Java

Advanced OOP Concepts in Java Advanced OOP Concepts in Java Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring 09/28/2001 1 Overview

More information

Web Development in Java

Web Development in Java Web Development in Java Detailed Course Brochure @All Rights Reserved. Techcanvass, 265, Powai Plaza, Hiranandani Garden, Powai, Mumbai www.techcanvass.com Tel: +91 22 40155175 Mob: 773 877 3108 P a g

More information

Lecture 1 Introduction to Android

Lecture 1 Introduction to Android These slides are by Dr. Jaerock Kwon at. The original URL is http://kettering.jrkwon.com/sites/default/files/2011-2/ce-491/lecture/alecture-01.pdf so please use that instead of pointing to this local copy

More information

Programmation 2. Introduction à la programmation Java

Programmation 2. Introduction à la programmation Java Programmation 2 Introduction à la programmation Java 1 Course information CM: 6 x 2 hours TP: 6 x 2 hours CM: Alexandru Costan alexandru.costan at inria.fr TP: Vincent Laporte vincent.laporte at irisa.fr

More information

Java How to Program, 5/e Test Item File 1 of 5

Java How to Program, 5/e Test Item File 1 of 5 Java How to Program, 5/e Test Item File 1 of 5 Chapter 8 Section 8.1 8.1 Q1: Object-Oriented Programming encapsulates: a.data and methods. b.information hiding. c.classes. d.adjectives ANS: a. Data and

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program

More information

CS193j, Stanford Handout #4. Java 2

CS193j, Stanford Handout #4. Java 2 CS193j, Stanford Handout #4 Winter, 2002-03 Nick Parlante Java 2 Student Java Example As a first example of a java class, we'll look at a simple "Student" class. Each Student object stores an integer number

More information