Chapter 10 Object-Oriented Programming

Size: px
Start display at page:

Download "Chapter 10 Object-Oriented Programming"

Transcription

1 Chapter 10 Object-Oriented Programming Software Reuse and Independence Objects, Classes, and Methods Inheritance and Dynamic Binding Language Examples: Java, C++, Smalltalk Design Issues and Implementation Issues

2 Why Objects? Benefits of Object-Oriented Programming Dynamic Control The exact behavior of functions are determined according to the object itself. Code Reuse The behaviors of objects can be redefined or extended based on the previous behaviors. Independent Modifiability Redefinition of behaviors does not incur the recompilation of the previous codes. Some languages, such as Smalltalk, allow behavior to change even during execution! Programming Languages 2

3 Fundamental Concepts Classes and Methods The class is an ADT mechanism that additionally offers good initialization control (constructors). Inheritance A class can extend another class (it becomes a subclass), thus enabling the reuse of all (or some) of the previouslywritten code. Dynamic Binding A variable of a class can contain an object of a subclass, and all subclass-modified behavior automatically applies. Programming Languages 3

4 Objects and Classes Object an abstraction of real world objects an object is consisted of the state: defined by variables (instance variables) the behavior: defined by functions (methods) Class a blueprint for a set of objects the objects of a class is called instances of the class The True Story The class concept is devised to share the methods of similar objects. Programming Languages 4

5 Class Complex in Java public class Complex { public Complex() { re = 0; im = 0; public Complex (double realpart, double imagpart) { re = realpart; im = imagpart; public double realpart() { return re; public double imaginarypart() { return im; public Complex add( Complex c ) { return new Complex(re + c.realpart(), Special methods called constructors. The first constructor is a default constructor which takes no parameters Private entities are inaccessible from the client codes. im + c.imaginarypart()); public Complex multiply (Complex c) { return new Complex(re * c.realpart() - im * c.imaginarypart(), re * c.imaginarypart() + im * c.realpart()); private double re, im; The declaration of instance variables Programming Languages 5

6 Using the Complex Class public class ComplexUser { public static void main(string[] args) { Complex z,w; z = new Complex (1,2); w = new Complex (-1,1); z = z.add(w).multiply(z); System.out.println(z.realpart()); System.out.println(z.imaginarypart()); A method add of the object z is invoked. (A message add(w) is sent to z.) The object w is a parameter of the method. Creating Complex objects. Complex constructors are invoked. Programming Languages 6

7 Complex Using Polar Coordinates public class Complex { public Complex() { radius = 0; angle = 0; public Complex (double realpart, double imagpart) { radius = Math.sqrt(realpart*realpart + imagpart*imagpart); angle = Math.atan2(imagpart,realpart); public double realpart() { return radius * Math.cos(angle); public double imaginarypart() { return radius * Math.sin(angle); public Complex add( Complex c ) { return new Complex(realpart() + c.realpart(), imaginarypart() + c.imaginarypart()); public Complex multiply (Complex c) { return new Complex(realpart() * c.realpart() - imaginarypart() * c.imaginarypart(), realpart() * c.imaginarypart() + imaginarypart() * c.realpart()); private double radius, angle; Note that the public interfaces are not changed! Programming Languages 7

8 Inheritance A class B may be designed by extending an existing class A public class B extends A {... In this case, A is called the superclass of B and B is called the subclass of A B inherits all the instance variables and methods of A This makes an is-a relation: B is-a A When the classes are treated as types, B is a subtype of A and A is a supertype of B Subtype Principle An object of a subtype may be sued anywhere an object of its supertype is legal Programming Languages 8

9 The Object Class in Java The Class Object The topmost class in the Java class hierarchy All classes implicitly extend the class Object public class A {... means public class A extends Object {... Overriding the Methods The methods of a superclass may be customized for a subclass. This redefinition of methods is called overriding Let s override some methods in the Object class Programming Languages 9

10 Class Complex in Java public class Complex { //... previous code as before // Must keep Object class definition for overriding public boolean equals (Object obj) { Complex c = (Complex) obj; return re == c.realpart() && im == c.imaginary part(); public String tostring() { return re + " + " + im + "i"; The methods equals and tostring are overridden. Downcasting: if obj is not a Complex object, runtime error will be occurred. Complex z = new Complex(1,1); Complex x = new Complex(1,1); if (x.equals(z)) System.out.println("ok!"); System.out.println(z); The result of the above code will be: ok! i Programming Languages 10

11 Abstract Class and Abstract Methods Abstract Method a method whose implementation is not defined AKA deferred method abstract methods should be overridden Abstract Class a class which contains a abstract method an abstract class cannot have instances public abstract class ClosedFigure { public ClosedFigure (Point c) { center = c; //... public abstract double area(); private Point center; Programming Languages 11

12 Subclasses of ClosedFigure Class public class Circle extends ClosedFigure { public Circle( Point c, double r) { super(c); radius = r; //... public double area() { return Math.PI * radius double * h) radius; { super(c); private double radius; width = w; public class Rectangle extends ClosedFigure { public Rectangle (Point c, double w, height = h; //... public double area() { return width * height; Invoke the constructor of the superclass private double width; private double height; Programming Languages 12

13 Using the ClosedFigure Classes public class User { public static void main(string[] args) { Point x,y; ClosedFigure f; Rectangle r; Circle c; x = new Point(0,0); y = new Point(1,-1); r = new Rectangle(x,1,1); c = new Circle(y,1); f = r; System.out.println(f.area()); f = c; System.out.println(f.area()); Dynamic Binding Note that the dynamic binding of the method invocations The 1 st call to f.area() calls the method of r The 2 nd call to f.area() calls the method of c Programming Languages 13

14 Inheritance Graph Inheritance graphs show the superclass-subclass relationship AKA class diagram Example ClosedFigure Rectangle Circle Programming Languages 14

15 Multiple Inheritance Multiple Inheritance a class inherits from two or more superclasses Repeated Inheritance Problem the subclass object may have multiple copy of multiply inherited class objects. A A A B C B C D D Programming Languages 15

16 Multiple Inheritance in Languages Java Java does not support the multiple inheritance of classes. Java supports multiple inheritance of interfaces. An interface is similar to an abstract class where all the methods are abstract and implicitly public. An interface can be used as a type name. C++ C++ supports multiple inheritance of classes. The repeated inheritance problem is controlled by virtual inheritance. Programming Languages 16

17 Interface Example public interface LinkableObject { LinkableObject next(); void linkto( LinkableObject p); public class LinkableComplex extends Complex implements LinkableObject { private LinkableObject link; public LinkableObject next() { return link; public void linkto( LinkableObject p) { link = p; public LinkableComplex( double re, double im) { super(re,im); link = null; The class LinkableComplex is a subclass of Complex with additional functionality of the interface LikableObject. Programming Languages 17

18 Polymorphism in Java Ad-hoc Polymorphism (Overloading) Java supports overloading of methods Subtype Polymorphism Java supports subtype polymorphism using dynamic binding of method invocations Parametric Polymorphism Currently, Java does not support parametric polymorphism, such as template. Parametric polymorphism can be simulated basedobject approach Programming Languages 18

19 LinkableObject (in Java) public class LinkableObject { public LinkableObject( Object d ) { link = null; item = d; public LinkableObject( Object d, LinkableObject link) { this.link = link; item = d; public LinkableObject next() { return link; public void linkto( LinkableObject p) { link = p; public Object data() { return item; private LinkableObject link; private Object item; Note that a LinkableObject may link arbitrary Object. Programming Languages 19

20 Queue (in Java) public class Queue { public Queue() { rear = null; public boolean empty() { return rear == null; public LinkableObject front() { return rear.next(); public void dequeue() { if (front() == rear) rear = null; else rear.linkto(front().next()); public void enqueue( LinkableObject item) { if (empty()) { rear = item; rear.linkto(item); else { item.linkto(front()); rear.linkto(item); rear = item; private LinkableObject rear; The class Queue is designed using the class LikableObject in order to link any kind of objects. Programming Languages 20

21 Based-Object Approach LinkableObject r = new LinkableObject(new Double(1.2)); LinkableObject i = new LinkableObject(new Integer(42)); LinkableObject c = new LinkableObject(new Complex(1,-1)); Queue q = new Queue(); q.enqueue(r); q.enqueue(i); q.enqueue(c); q.dequeue(); System.out.println(q.front().data()); // prints 42 Based-object approach may need RTTI (run-time type identification): Object obj = q.front().data(); if (obj instanceof Double) System.out.println(((Double)obj).doubleValue()*2); else if (obj instanceof Integer) System.out.println(((Integer)obj).intValue()*2); else if (obj instanceof Complex) System.out.println(((Complex)obj).add((Complex)obj)); Programming Languages 21

22 Dynamic Nature of Objects Object Allocation and Deallocation Fully Manual Fully Automatic Hybrid: manual allocation and automatic deallocation Method Invocation Static Binding: methods are invoked according to the class of object variable Dynamic Binding: methods are invoked according to the actual receiver object of the message Programming Languages 22

23 Dynamic Binding Example class A { void p() { System.out.println("A.p"); void q() { System.out.println("A.q"); void f() { p(); // interpreted as this.p(); q(); // interpreted as this.q(); The program prints: class B extends A { void p() A.p { System.out.println("B.p"); void q() A.q The 1st a.f() call { System.out.println("B.q"); B.p super.q(); B.q The 2nd a.f() call A.q public class VirtualExample { public static void main(string[] args) { A a = new A(); a.f(); a = new B(); a.f(); Programming Languages 23

24 C++ A complex, multiparadigm language. Has almost every conceivable feature. Some of its problems are inherited from C. Programs can be very fast and concise. For OO programming, problems come from (not in order of importance): Multiple inheritance Operator overloading Lack of garbage collection Interaction with templates Focus on execution speed Inadequate standard library Programming Languages 24

25 Defining Classes in C++ Different Terms in Different Languages C++ Community Java Community base class derived class member function member variable superclass subclass method instance variable Class declaration and definition may be separated To define a member function outside of a class, use the scope resolution operator. The member functions defined inside of a class are automatically regarded as inline functions Programming Languages 25

26 LinkableObject (in C++) class LinkableObject { public: LinkableObject() : link(0) { The initializers are used to ensure that the instance variables are initialized prior to the execution of the body of the constructor. LinkableObject (LinkableObject* p) : link(p) { LinkableObject* next() { return link; void linkto (LinkableObject* p) { link = p; The access modifiers (public, private: private, etc.) are not applied for LinkableObject* link; every member. Rather, they ; declare sections. The default section is private. Programming Languages 26

27 Queue Declaration (in C++) class Queue { public: Queue() : rear(0) { bool empty() { return rear == 0; implicitly inline but not always void enqueue(linkableobject* item); void dequeue(); LinkableObject* front() { return rear->next(); ~Queue(); protected: // demo - may not be appropriate LinkableObject* rear; ; Programming Languages 27

28 Queue Methods (in C++) void Queue::enqueue(LinkableObject* item) { if (empty()) { rear = item; rear->linkto(item); else { item->linkto(front()); rear->linkto(item); rear = item; void Queue::dequeue() { if (front() == rear) rear = 0; else rear->linkto(front()->next()); Queue::~Queue() // demo code - may result in dangling refs { while (!empty()) { LinkableObject* temp = front(); dequeue(); delete temp; Note that the scope resolution operators are used. Currently, LinkableObject objects contains no data. Define a derived class of LikableObject to store any useful data. Programming Languages 28

29 LinkableInt (in C++) class LinkableInt : public LinkableObject { public: LinkableInt(int d) : item(d) { int data() { return item; private: int item; ; The Queue can be used as following:... Queue q; LinkableInt* x = new LinkableInt(42); q.enqueue(x); x = static_cast<linkableint*>(q.front()); cout << x->data() << endl; // prints Programming Languages 29

30 Parametric Polymorphism in C++ C++ supports every kinds of polymorphism C++ supports overloading (ad-hoc polymorphism) C++ supports inheritance (subtype polymorphism) C++ has template (parametric polymorphism) What about based-object approach? C++ has no top-most class based-object approach may be simulated using generic pointers (void* pointers) but generic pointers do not support dynamic binding Programming Languages 30

31 Template Queue (in C++) template<typename T> class Queue { public: Queue() : rear(0) { int empty() { return rear == 0; void enqueue (T item); void dequeue (); T front() { return rear->next->data; ~Queue(); protected: class Linkable { public: T data; Linkable* next; ; Linkable* rear; ; Class Linkable is declared as a nested class. Programming Languages 31

32 Template Methods (in C++) template <typename T> void Queue<T>::enqueue(T item) { Linkable* temp = new Linkable; temp->data = item; if (empty()) { rear = temp; rear->next = temp; else { temp->next = rear->next; rear->next = temp; rear = temp; template <typename T> void Queue<T>::dequeue() { Linkable* temp = rear->next; if (temp == rear) rear = 0; else rear->next = rear->next->next; delete temp; template <typename T> Queue<T>::~Queue() { while (!empty()) dequeue(); The methods should be defined as template functions because the class Queue is declared to take a type parameter T. The Queue may be used as following (Notice that the type parameter is given):... Queue<int> q; q.enqueue(42); int x = q.front(); q.dequeue();... Programming Languages 32

33 Dynamic Binding in C++ class A { public: void p() { cout << "A::p\n" ; virtual void q() { cout << "A::q\n" ; void f() { p(); q(); ; class B : public A { public: void p() { cout << "B::p\n" ; void q() { cout << "B::q\n" ; ; int main() { A a; B b; a.f(); b.f(); a = b; a.f(); The program prints: A::p A::q A::p B::q A::p A::q The 1st a.f() call The b.f() call The 2nd a.f() call Programming Languages 33

34 Virtual Functions Virtual functions support dynamic binding The virtual property of a member function is also inherited (i.e. the function which overrides a virtual function is implicitly virtual) Pure virtual function is an abstract function class ClosedFigure // an abstract class { public: virtual double area() = 0; // pure virtual... ; Programming Languages 34

35 Controlling Multiple Inheritance C++ supports two kinds of inheritance Shared Inheritance Repeated Inheritance A A A B C B C D D To get shared inheritance, use the keyword virtual when deriving a class: class A {...; class B : virtual public A {...; class C : virtual public A {...; class D : public B, public C {...; This is the default. Programming Languages 35

36 Smalltalk Ahead of its time: consistent design and rich library. Dynamic (like Lisp): variables have no specified type. The class structure is the type system. Everything is an object, including numbers. So somewhat lacking in efficiency. There are no explicit protection markers: all data is implicitly private, all methods implicitly public. Syntax is peculiar, and tied to the runtime environment. Typically only a global namespace for classes, so I will call the example class MyPoint. Programming Languages 36

37 Smalltalk Brief History due to Alan Kay at Xerox PARC (early 1970s) arose out of a research project (Dynabook Project) Features purely object-oriented (everything is an object) dynamic (dynamic binding and dynamic memory management) tightly coupled with the runtime environment implicit protection (all data are private, all methods are public) peculiar syntax (see the next slide) Programming Languages 37

38 Some Notes on Smalltalk Syntax Method names are called selectors unary selector q front means q.front() in C++ or Java keyword selector table insert: anitem at: anindex means table.insert(anitem,anindex) in C++ or Java binary selector: one or two symbols means (2.+(3)).+(4) Arrows for return and assignment upward arrow ( or ^) denotes a return left arrow ( or <-) denotes an assignment Programming Languages 38

39 Class Definition Syntax Class name: <name> Superclass: <name> Instance variables: <list-of-names> Methods: <name> <implementation> <name> <implementation> Programming Languages 39

40 LinkableObject Class (in Smalltalk) Class name: LinkableObject Superclass: Object Instance variables: link Methods: next Two methods, next and linkto, ^ link are defined. linkto: anobject link <- anobject Class Method: new: alinkableobject ^ (self new) linkto: alinkableobject overriding the default new method of the metaclass Class Programming Languages 40

41 local variable Queue Class (in Smalltalk) Class name: Queue object identity test Superclass: Object Instance variables: rear Methods: empty ^ rear == nil front ^ rear next enqueue: alinkableobject self empty iftrue: [ rear <- alinkableobject. code block rear linkto: rear ] iffalse: [ alinkableobject linkto: rear next. rear linkto: alinkableobject. rear <- alinkableobject ] dequeue temp temp <- self front. statement delimiter (rear == temp) iftrue: [ rear <- nil ] iffalse: [ rear linkto: (temp next) ] Programming Languages 41

42 Test Code for Queue (in Smalltalk) q <- Queue new. x <- LinkableObject new. y <- LinkableObject new. q enqueue: x. q enqueue: y. y <- q front. "now y == x" q dequeue. q dequeue. "now q is empty" Programming Languages 42

43 Implementation Issues Implementing Object Allocation similar to normal record implementation subclass objects need more space than superclass ones Implementing Dynamic Binding Naïve Implementation search the entire class hierarchy during runtime Advanced Implementation construct a method table during compile time a fixed offset can be statically determined for each method attach the pointer of the table to corresponding objects for each object creation Programming Languages 43

44 Object Allocation The following implementation allows in-place overwrite of subclass objects by superclass objects. class Point {... private double x,y; class ColoredPoint extends Point {... private Color color; Point object space for x space for y coloredpoint object space for x space for y space for color Programming Languages 44

45 Virtual Method Table The VMT (virtual method table) pointer is attached to each objects Assume that Class Point has only one method moveto Class ColoredPoint has only one method getcolor Point object VMT for Point coloredpoint object VMT for coloredpoint VMT pointer moveto VMT pointer moveto space for x space for y space for x space for y space for color getcolor Programming Languages 45

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

Object-oriented Programming. Object-oriented Programming

Object-oriented Programming. Object-oriented Programming 2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language

More information

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public

More information

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual

More information

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

CH. 2 OBJECT-ORIENTED PROGRAMMING

CH. 2 OBJECT-ORIENTED PROGRAMMING CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

Week 7. Statically-typed OO languages: C++ Closer look at subtyping C++ & Subtyping Week 7 Statically-typed OO languages: C++ Closer look at subtyping Why talk about C++? C++ is an OO extension of C Efficiency and flexibility from C OO program organization from Simula

More information

Some instance messages and methods

Some instance messages and methods Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation CSE 452: Programming Languages Data Abstraction and Object-Orientation Previous Lecture Abstraction Abstraction is the elimination of the irrelevant and the amplification of the essential Robert C Martin

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL FUNCTIONS Chapter 10 1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions

More information

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed 1 1 COMP200 INHERITANCE OOP using Java, from slides by Shayan Javed 2 Inheritance Derive new classes (subclass) from existing ones (superclass). Only the Object class (java.lang) has no superclass Every

More information

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D) DATA TYPES CS 403: Types and Classes Stefan D. Bruda Fall 2017 Algorithms + data structures = programs Abstractions of data entities highly desirable Program semantics embedded in data types Data types

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

C++ Programming: Polymorphism

C++ Programming: Polymorphism C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

History C++ Design Goals. How successful? Significant constraints. Overview of C++

History C++ Design Goals. How successful? Significant constraints. Overview of C++ 1 CS 242 History C++ John Mitchell C++ is an object-oriented extension of C C was designed by Dennis Ritchie at Bell Labs used to write Unix based on BCPL C++ designed by Bjarne Stroustrup at Bell Labs

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information

C11: Garbage Collection and Constructors

C11: Garbage Collection and Constructors CISC 3120 C11: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/5/2017 CUNY Brooklyn College 1 Outline Recap Project progress and lessons

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

References: Chapters 10 and 11 Chapters 8, and 12( 2 and 3)

References: Chapters 10 and 11 Chapters 8, and 12( 2 and 3) Topic V Object-oriented languages : Concepts and origins SIMULA and Smalltalk References: Chapters 10 and 11 of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 8, and 12( 2 and

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Subtyping (Dynamic Polymorphism)

Subtyping (Dynamic Polymorphism) Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter

More information

Inheritance and object compatibility

Inheritance and object compatibility Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

C++ Yanyan SHEN. slide 1

C++ Yanyan SHEN. slide 1 C++ Yanyan SHEN slide 1 History C++ is an object-oriented extension of C Designed by Bjarne Stroustrup at Bell Labs His original interest at Bell Labs was research on simulation Early extensions to C are

More information

Lecture Notes Chapter #9_b Inheritance & Polymorphism

Lecture Notes Chapter #9_b Inheritance & Polymorphism Lecture Notes Chapter #9_b Inheritance & Polymorphism Inheritance results from deriving new classes from existing classes Root Class all java classes are derived from the java.lang.object class GeometricObject1

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Islamic University of Gaza Faculty of Engineering Computer Engineering Department Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B

More information

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

Polymorphism. Zimmer CSCI 330

Polymorphism. Zimmer CSCI 330 Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)

More information

CS153: Compilers Lecture 11: Compiling Objects

CS153: Compilers Lecture 11: Compiling Objects CS153: Compilers Lecture 11: Compiling Objects Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 3 due today Project 4 out Due Thursday Oct 25 (16 days) Project 5 released

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p. Preface to the Second Edition p. iii Preface to the First Edition p. vi Brief Contents p. ix Introduction to C++ p. 1 A Review of Structures p. 1 The Need for Structures p. 1 Creating a New Data Type Using

More information

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc. Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures

More information

More Relationships Between Classes

More Relationships Between Classes More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to

More information

Simula 67. Simula and Smalltalk. Comparison to Algol 60. Brief history. Example: Circles and lines. Objects in Simula

Simula 67. Simula and Smalltalk. Comparison to Algol 60. Brief history. Example: Circles and lines. Objects in Simula CS 242 Simula 67 Simula and Smalltalk John Mitchell First object-oriented language Designed for simulation Later recognized as general-purpose prog language Extension of Algol 60 Standardized as Simula

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan Programming Languages 2nd edition Tucker and Noonan" Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance..."

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

More information

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

Function Overloading

Function Overloading Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

Object typing and subtypes

Object typing and subtypes CS 242 2012 Object typing and subtypes Reading Chapter 10, section 10.2.3 Chapter 11, sections 11.3.2 and 11.7 Chapter 12, section 12.4 Chapter 13, section 13.3 Subtyping and Inheritance Interface The

More information

Administrivia. Java Review. Objects and Variables. Demo. Example. Example: Assignments

Administrivia. Java Review. Objects and Variables. Demo. Example. Example: Assignments CMSC433, Spring 2004 Programming Language Technology and Paradigms Java Review Jeff Foster Feburary 3, 2004 Administrivia Reading: Liskov, ch 4, optional Eckel, ch 8, 9 Project 1 posted Part 2 was revised

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Increases Program Structure which results in greater reliability. Polymorphism

Increases Program Structure which results in greater reliability. Polymorphism UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the

More information

First IS-A Relationship: Inheritance

First IS-A Relationship: Inheritance First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class

More information

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism CS 112 Programming 2 Lecture 06 Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism rights reserved. 2 Motivation Suppose you want to define classes to model circles, rectangles, and

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers Code Shape II Objects & Classes Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 L-1 Administrivia Semantics/type check due next Thur. 11/15 How s it going? Reminder: if you want

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College CISC 3115 TY3 C09a: Inheritance Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/20/2018 CUNY Brooklyn College 1 Outline Inheritance Superclass/supertype, subclass/subtype

More information

Type Analysis. Type Checking vs. Type Inference

Type Analysis. Type Checking vs. Type Inference Type Analysis Is an operator applied to an incompatible operand? Type checking: Static: Check for type compatibility at compile time Dynamic: Check for type compatibility at run time Type analysis phase

More information

The Java Programming Language

The Java Programming Language The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation

More information

C10: Garbage Collection and Constructors

C10: Garbage Collection and Constructors CISC 3120 C10: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/5/2018 CUNY Brooklyn College 1 Outline Recap OOP in Java: composition &

More information

COMP200 ABSTRACT CLASSES. OOP using Java, from slides by Shayan Javed

COMP200 ABSTRACT CLASSES. OOP using Java, from slides by Shayan Javed 1 1 COMP200 ABSTRACT CLASSES OOP using Java, from slides by Shayan Javed Abstract Classes 2 3 From the previous lecture: public class GeometricObject { protected String Color; protected String name; protected

More information

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini 24. Inheritance Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Superclasses and Subclasses Inheritance

More information

This examination has 11 pages. Check that you have a complete paper.

This examination has 11 pages. Check that you have a complete paper. MARKING KEY The University of British Columbia MARKING KEY Computer Science 252 2nd Midterm Exam 6:30 PM, Monday, November 8, 2004 Instructors: K. Booth & N. Hutchinson Time: 90 minutes Total marks: 90

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information