Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Size: px
Start display at page:

Download "Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition"

Transcription

1 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition

2 Chapter Objectives 2

3 Chapter Objectives (continued) 3

4 Chapter Objectives (continued) C# Programming: From Problem Analysis to Program Design 4

5 Object-Oriented Language Features 5

6 Component-Based Development Figure 11-1 Component-based development 6

7 Component-Based Development (continued) 7

8 Component-Based Development (continued) C# Programming: From Problem Analysis to Program Design 8

9 Inheritance 9

10 Inheriting from the Object Class 10

11 Inheriting from Other.NET FCL Classes System.Windows.Forms.Form C# Programming: From Problem Analysis to Program Design 11

12 Inheriting from Other.NET FCL Classes Derived class Figure 11-3 Derived class Base class C# Programming: From Problem Analysis to Program Design 12

13 Creating Base Classes for Inheritance C# Programming: From Problem Analysis to Program Design 13

14 Class Diagram: Person - Student Base class Sub-class (Derived) 14

15 Person Class (Base) 1 of 2 class Person //data members private string lastname = "n.a"; private string firstname= "n.a"; 1 private int age = 0; private string occupation = "n.a"; 2 //Properties // Verbose style - Property for last name public string LastName get return lastname; } set lastname = value; } } // Properties using C# 7.0 style- Expression Bodied Method notation public string FirstName get => firstname; set => firstname = value; } public int Age get return age; } set => age = Math.Abs(value); } public string Occupation get return occupation; } set => occupation = value; } 15

16 Person Class (Base) 2 of 2 // Constructor with zero arguments public Person() } } // Constructor with four arguments public Person( string lnamevalue, string fnamevalue, int agevalue) LastName = lnamevalue; FirstName = fnamevalue; Age = agevalue; } //user-defined methods (new formatting feature C# 7.0) public override string ToString() return string.format( $"Person [ " + $"First= FirstName} Last= LastName} " + $"Age= age} " + $"Ocuppation= Occupation} ]"); } //a virtual method could be overridden by its derived sub-classes public virtual int GetSleepAmount() return 8; } 16

17 6 Student Class (Derived/Sub class) 1 of 2 class Student : Person 7 //data members private string major = "not declared yet"; private double gpa = 0.0; private int studentid = 0; 8 //properties (bodied expressions) public string Major get => major; set => major = value; } public double Gpa get => gpa; set => gpa = value; } public int StudentId get=> studentid; set=> studentid = value; } //constructors public Student() :base() } 9 public Student(string lnamevalue,string fnamevalue, int agevalue, int idvalue, string majorvalue, double gpavalue) :base(lnamevalue, fnamevalue, agevalue) StudentId = idvalue; Major = majorvalue; Gpa = gpavalue; } 17

18 Student Class (Derived/Sub class) 2 of 2 10 //user-defined methods public override string ToString() return string.format( $"\nstudent [ ID= StudentId} Major= Major} GPA= Gpa}" + $"\n\t" + base.tostring() + $" ]"); } 11 public override int GetSleepAmount() //return base.getsleepamount(); return 6; } } 18

19 Access Modifiers Ancestor private... protected public Subclass Only ancestor's public & protected members are visible 19

20 Creating Base Classes for Inheritance 1 class Person Base class //data members private string lastname = "n.a"; private string firstname= "n.a"; private int age = 0; private string occupation = "n.a"; All derived classes will include these four attributes All data members are customarily defined private. Good practice! These default values could be used by zero-args constructor 20

21 Classic verbose style Properties (Verbose Style) 2 // Property for last name public string LastName } get } set } return lastname; lastname = value; Private data member RHS of an assignment 21

22 Properties (Compressed notation) => (~Person() =>... //Properties (using Expression Bodied Method's notation) public string Occupation get => occupation; set => occupation = value; } 2 public string LastName get=> lastname; set=> lastname = value; } public string FirstName get => firstname; set => firstname = value; } public int Age get return age; } set => age = Math.Abs(value); } 22

23 Public Access Modifier LastName lastname Property field/data member 23

24 Creating Base Classes for Inheritance: Constructors 3 // Constructor with zero arguments public Person( ) } // Constructor with four arguments public Person (string lnamevalue,string fnamevalue, } int agevalue) LastName = lnamevalue; FirstName = fnamevalue; Age = agevalue; All the object's data-members will used their already declared default values Notice, constructor is a method, has same name as class (Person), has no return type, and is overloaded Properties 24

25 Overriding Methods public override string ToString( ) // Defined in Person public virtual int GetSleepAmt( ) // Defined in Person virtual, abstract, override override 25

26 Overriding Methods The Person class example overrides ToString() Base class ToString( ) method 4 //using string interpolation - new C# 6.0 formatting feature public override string ToString() return string.format( $"\nperson [ ID= IdNumber} Age= age} " + $"First= FirstName} Last= LastName} " + $"Ocuppation= Occupation} ]"); } Person Object Object 26

27 Virtual Methods (continued) 5 //a virtual method could be overridden by its derived sub-classes public virtual int GetSleepAmount() return 8; } HeavyCoffeeDrinker 27

28 Virtual Methods (continued) Object 28

29 Creating Derived Classes C# Programming: From Problem Analysis to Program Design 29

30 Derived Classes class Student : Person Reference to base class 6 //data members private string major = "not declared yet"; private double gpa = 0.0; private int studentid = 0; Additional subclass data members //properties (bodied expressions)... //constructors public Student() :base() } Indicates which base class constructor to use C# Programming: From Problem Analysis to Program Design 30

31 Calling the Base Constructor 9 //all-arguments constructor public Student(string fnamevalue, string lnamevalue, int agevalue, string majvalue, string studentidvalue) : base(lnamevalue, fnamevalue, agevalue) // calling base constructor } Major = majvalue; StudentId = studentidvalue; Use base constructor to create a Person object 31

32 Calling the Base Constructor (cont) Student s2 = new Student("Parker", "Peter", 21, , "CHEM", 4.0); Student anotherstudent = new Student(); Person Student new Student() 32

33 Calling Overridden Methods of the Base Class return base.getsleepamt( ) // Calls GetSleepAmt( ) in // parent class C# Programming: From Problem Analysis to Program Design 33

34 Relationship between the Person and Student Classes Figure 11-5 Inheritance class diagram 34

35 35

36 Abstract Classes 36

37 Abstract Classes Person abstract public abstract class Person... 37

38 Abstract Classes Person new Person() new Student() 38

39 Abstract Methods 39

40 Abstract Methods (continued) [access modifier] abstract returntype MethodIdentifier // No } included ([parameter list]) ; 40

41 Abstract Methods (continued) Student SetHobby public override void SetHobby(string activityvalue) } public abstract void SetHobby(string activityvalue); //assume List<string> listhobbies has been added to data members listhobbies.add(activityvalue); Defined in Person Defined in Student 41

42 Sealed Classes Sealed public sealed class Student public class UndergraduateStudent : Student 42

43 Sealed Methods public virtual void RaiseSalary(double incrementvalue)...} public sealed override void RaiseSalary(double incrementvalue)...} 43

44 Partial Classes partial public abstract partial class Person 44

45 GeometricObject Example 1 of 9 45

46 1 GeometricObject Example 2 of 9 public abstract class GeometricObject private string color = "White"; private DateTime datecreated = new DateTime(2017, 12, 31, 23, 59, 59); private bool filled = false; // Properties (classic style) public string Color get return color; } set string temp = value.toupper(); char firstletter = temp[0]; color = firstletter + temp.substring(1).tolower(); } } public DateTime DateCreated get return datecreated; } private set datecreated = value; } } public bool Filled get return filled; } set filled = value; } } 2 //constructors public GeometricObject() Color = "White"; Filled = true; DateCreated = DateTime.Now; } 46

47 GeometricObject Example 3 of public GeometricObject(string colorvalue, bool filledvalue) Color = colorvalue; Filled = filledvalue; DateCreated = DateTime.Now; } //user-defined methods public override string ToString() return string.format($"geometricobject [Color: Color}, " + $"Filled:Filled}, " + $"DateCreated:DateCreated.ToString("yyy-MM-dd")}]"); } //Observe that the following two methods have no body! //Descendants of the GeometricObject class MUST implement them. public abstract double GetArea(); public abstract double GetArea(int numdecimals); public abstract double GetPerimeter(); public virtual int CalculateCost() //this VIRTUAL method may be overridden by descendants //an arbitrary way to assess figure's cost int cost = 0; if (Color == "Gold" Color=="Silver") cost += 300; } if (filled) cost += 200; return cost; } } //GeometricObject 47

48 GeometricObject Example 4 of 9 7 class Circle : GeometricObject //data member(s) private double radius = 0; //properties public double Radius get return radius; } set radius = Math.Abs(value); } } 8 //constructor(s) public Circle() : base() Radius = 0; } public Circle(string colorvalue, bool filledvalue, double radiusvalue) :base(colorvalue, filledvalue) Radius = radiusvalue; } 48

49 GeometricObject Example 5 of //user-defined methods public override string ToString() //showing two possible versions of the ToString() method int option = 1; switch (option) case 1: //OPTION1. mixed message child + ancestor string ancestormsg = base.tostring(); string childmsg1 = string.format($"circle [Radius: Radius} ] "); return childmsg1 + " child of " + ancestormsg; case 2: //OPTION2. only child's msg string childmsg2 = string.format($"circle [Radius:Radius}, " + $"Color:Color}, Filled:Filled}, " + $"Created:DateCreated} ]"); return childmsg2; } return "Circle"; } //The following three methods override the empty definition imposed by ancestor class. //The base class demanded that its ABSTRACT METHODS must be implemented by its children. public override double GetArea() //NOTE: this method could be implemented instead as a read-only property //(see above defintion of property Area) return Math.PI * Math.Pow(Radius, 2); 49 }

50 11 12 GeometricObject Example 6 of 9 public override double GetArea(int numdecimals) //display area using a given number of decimal positions double area = Math.PI * Math.Pow(Radius, 2); string numformat = "0:N" + numdecimals + "}"; string strarea = string.format(numformat, area); return Convert.ToDouble(strArea); } public override double GetPerimeter() return 2 * Math.PI * Radius; } }//Circle 50

51 13 GeometricObject Example 7 of 9 class Rectangle : GeometricObject //data members private double height = 0; private double width = 0; //properties public double Width get return width; } set width = value; } } public double Height get return height; } set height = value; } } 14 //constructors public Rectangle() : base() Height = 0; Width = 0; } 51

52 GeometricObject Example 8 of public Rectangle(double widthvalue, double heightvalue, string colorvalue, bool filledvalue) :base(colorvalue, filledvalue) Width = widthvalue; Height = heightvalue; } //user defined methods public override string ToString() return string.format($"rectangle [Height:Height:N2}, Width:Width:N2}, " + $"Color:Color}, Filled:Filled}, " + $"Created:DateCreated} ]"); } //The following three methods override the empty definition imposed by ancestor class. //The base class demanded that its ABSTRACT METHODS must be implemented by its children. public override double GetArea() return Height * Width; } public override double GetArea(int numdecimals) //display area using a given number of decimal positions double area = Height * Width; string numformat = "0:N" + numdecimals + "}"; string strarea = string.format(numformat, area); return Convert.ToDouble(strArea); } 52

53 17 GeometricObject Example 9 of 9 public override double GetPerimeter() return 2 * (Height + Width); } } //Rectangle 53

54 Interfaces 54

55 Using.NET Interfaces Icomparable CompareTo() this this.compareto(other) other this this this other other other 55

56 Using.NET Interfaces public class Person : IComparable<Person> public virtual int CompareTo(Person other) if (this.age == other.age) return 0; else if (this.age > other.age) return 1; else return -1; }. 56

57 Using.NET Interfaces Person p1 = new Person("Prince", "Diane", 22); Person p2 = new Person(); if (p1.compareto(p2)!=0) Console.WriteLine("Different people!"); } 57

58 Polymorphism ToString( ) 58

59 Generics public class Stack<T> private T[] items; private int stackpointer = 0; public Stack(int size) } items = new T[size]; Generic Stack class 59

60 Generic Classes (continued) public T Pop( ) return items[--stackpointer]; } } public void Push(T anitem) items[stackpointer] = anitem; stackpointer++; } 60

61 Generic Methods 61

62 Generic Methods (continued) public void SwapData <T> (ref T first, ref T second) T temp; temp = first; first = second; second = temp; } //To call the method, specify the type following method name SwapData <string> (ref firstvalue, ref secondvalue); 62

63 Dynamic C# Programming: From Problem Analysis to Program Design 63

64 Dynamic Data Type 64

65 Dynamic Data Type (continued) dynamic intvalue = 1000; dynamic stringvalue = "C#"; dynamic decimalvalue = 23.45m; dynamic adate = System.DateTime.Today; Console.WriteLine("0} 1} 2} 3}", intvalue, stringvalue, decimalvalue, adate); 1000C# /16/ :00:00 AM Si 65

66 var Data Type var 66

67 var Data Type (continued) var somevalue = 1000; C# Programming: From Problem Analysis to Program Design 67

68 StudentGov Application Example Figure Problem specification for StudentGov example C# Programming: From Problem Analysis to Program Design 68

69 StudentGov Application Example (continued) Table 11-1 Data fields organized by class C# Programming: From Problem Analysis to Program Design 69

70 StudentGov Example (continued) Figure Prototype for StudentGov example C# Programming: From Problem Analysis to Program Design 70

71 StudentGov Example (continued) Figure Class diagrams for StudentGov example C# Programming: From Problem Analysis to Program Design 71

72 StudentGov Example (continued) Figure References added to StudentGov example C# Programming: From Problem Analysis to Program Design 72

73 StudentGov Example (continued) Figure References added to StudentGov example (continued) C# Programming: From Problem Analysis to Program Design 73

74 StudentGov Example (continued) Table 11-2 PresentationGUI property values C# Programming: From Problem Analysis to Program Design 74

75 StudentGov Example (continued) Table 11-2 PresentationGUI property values (continued) C# Programming: From Problem Analysis to Program Design 75

76 StudentGov Example (continued) Table 11-2 PresentationGUI property values (continued) C# Programming: From Problem Analysis to Program Design 76

77 StudentGov Example (continued) Table 11-2 PresentationGUI property values (continued) C# Programming: From Problem Analysis to Program Design 77

78 StudentGov Example (continued) Figure Setting the StartUp Project C# Programming: From Problem Analysis to Program Design 78

79 StudentGov Application Example (continued) Figure Part of the PresentationGUI assembly C# Programming: From Problem Analysis to Program Design 79

80 StudentGov Application Example (continued) Figure Output from StudentGov example C# Programming: From Problem Analysis to Program Design 80

81 Coding Standards C# Programming: From Problem Analysis to Program Design 81

82 Resources C# Programming: From Problem Analysis to Program Design 82

83 Chapter Summary 83

84 Chapter Summary (continued) 84

85 Chapter Summary (continued) C# Programming: From Problem Analysis to Program Design 85

86 APPENDIX Making Stand-Alone Components 86

87 APPENDIX Dynamic Link Library (DLL) C# Programming: From Problem Analysis to Program Design 87

88 Using Visual Studio to Create DLL Files Figure 11-6 Creating a DLL component 88

89 Build Instead of Run to Create DLL C# Programming: From Problem Analysis to Program Design 89

90 Build Instead of Run to Create DLL Figure 11-7 Attempting to run a class library file 90

91 Build Instead of Run to Create DLL (continued) using using PersonNamespace; C# Programming: From Problem Analysis to Program Design 91

92 Add Reference to Base Class One of the first things to do is Add a Reference to the Parent DLL 92

93 Add Reference to Base Class (continued) Use Browse button to locate DLL Figure 11-9 Add Reference dialog box 93

94 Add Reference to Base Class (continued) Figure Locating the Person.dll component 94

95 Adding a New Using Statement public class Student : Person 95

96 Adding a New Using Statement (continued) Notice fully qualified name public class Student : PersonNamespace.Person using PersonNamespace; // Use whatever name you // typed for the namespace for Person 96

97 Creating a Client Application to Use the DLL C# Programming: From Problem Analysis to Program Design 97

98 Creating a Client Application to Use the DLL (continued) 98

99 Declaring an Object of the Component Type public class PresentationGUI : System.Windows.Forms.Form private Student astudent; astudent = new Student(" ", "Maria", "Woo", "CS", "1111"); 99

100 Creating a Client Application to Use the DLL (continued) Figure PresentationGUI output referencing two DLLs 100

101 Using ILDASM to View the Assembly 101

102 Using ILDASM to View the Assembly (continued) C# Programming: From Problem Analysis to Program Design 102

103 ILDASM to View the Assembly Data fields.ctors are constructors IL code for the method Properties converted to methods 103

Lesson11-Inheritance-Abstract-Classes. The GeometricObject case

Lesson11-Inheritance-Abstract-Classes. The GeometricObject case Lesson11-Inheritance-Abstract-Classes The GeometricObject case GeometricObject class public abstract class GeometricObject private string color = "White"; private DateTime datecreated = new DateTime(2017,

More information

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn the

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

CS1150 Principles of Computer Science Objects and Classes

CS1150 Principles of Computer Science Objects and Classes CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8

More information

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof Abstract Class Lecture 21 Based on Slides of Dr. Norazah Yusof 1 Abstract Class Abstract class is a class with one or more abstract methods. The abstract method Method signature without implementation

More information

Creating Your Own Classes

Creating Your Own Classes 4 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives C# Programming: From Problem

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

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

Chapter 13 Abstract Classes and Interfaces

Chapter 13 Abstract Classes and Interfaces Chapter 13 Abstract Classes and Interfaces rights reserved. 1 Motivations You have learned how to write simple programs to create and display GUI components. Can you write the code to respond to user actions,

More information

Chapter 21- Using Generics Case Study: Geometric Bunch. Class: Driver. package csu.matos; import java.util.arraylist; public class Driver {

Chapter 21- Using Generics Case Study: Geometric Bunch. Class: Driver. package csu.matos; import java.util.arraylist; public class Driver { Chapter 21- Using Generics Case Study: Geometric Bunch In this example a class called GeometricBunch is made to wrap around a list of GeometricObjects. Circle and Rectangle are subclasses of GeometricObject.

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

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

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

In this lab, you will be given the implementation of the classes GeometricObject, Circle, and Rectangle, as shown in the following UML class diagram.

In this lab, you will be given the implementation of the classes GeometricObject, Circle, and Rectangle, as shown in the following UML class diagram. Jordan University Faculty of Engineering and Technology Department of Computer Engineering Object-Oriented Problem Solving: CPE 342 Lab-8 Eng. Asma Abdel Karim In this lab, you will be given the implementation

More information

Inheritance and Polymorphism. CSE 114, Computer Science 1 Stony Brook University

Inheritance and Polymorphism. CSE 114, Computer Science 1 Stony Brook University Inheritance and Polymorphism CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Model classes with similar properties and methods: Circles, rectangles

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

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

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

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive

More information

Abstract Classes Interfaces

Abstract Classes Interfaces Abstract Classes Interfaces Reading: Chapter 14 (skip 14.1,14.6, 14.12, and 14.13; read 14.7 lightly) Objectives 2 To design and use abstract classes ( 14.2-14.3). To specify common behavior for objects

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

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

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 22. Inheritance Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Inheritance Object-oriented programming

More information

CSC330 Object Oriented Programming. Inheritance

CSC330 Object Oriented Programming. Inheritance CSC330 Object Oriented Programming Inheritance Software Engineering with Inheritance Can customize derived classes to meet needs by: Creating new member variables Creating new methods Override base-class

More information

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class. Polymorphism CSC 0 Object Oriented Programming Polymorphism is considered to be a requirement of any true -oriented programming language (OOPL). Reminder: What are the other two essential elements in OOPL?

More information

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Constructor Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design these classes so to avoid redundancy? The

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 11: Inheritance and Polymorphism Part 1 Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad

More information

CIS 110: Introduction to computer programming

CIS 110: Introduction to computer programming CIS 110: Introduction to computer programming Lecture 25 Inheritance and polymorphism ( 9) 12/3/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Inheritance Polymorphism Interfaces 12/3/2011

More information

C# Programming: From Problem Analysis to Program Design. Fourth Edition

C# Programming: From Problem Analysis to Program Design. Fourth Edition C# Programming: From Problem Analysis to Program Design Fourth Edition Preface xxi INTRODUCTION TO COMPUTING AND PROGRAMMING 1 History of Computers 2 System and Application Software 4 System Software 4

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

CS 162, Lecture 25: Exam II Review. 30 May 2018

CS 162, Lecture 25: Exam II Review. 30 May 2018 CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you

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

Object Oriented System Development Paradigm. Sunnie Chung CIS433 System Analysis Methods

Object Oriented System Development Paradigm. Sunnie Chung CIS433 System Analysis Methods Object Oriented System Development Paradigm Sunnie Chung CIS433 System Analysis Methods OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object represents

More information

Data Structures and Other Objects Using C++

Data Structures and Other Objects Using C++ Inheritance Chapter 14 discuss Derived classes, Inheritance, and Polymorphism Inheritance Basics Inheritance Details Data Structures and Other Objects Using C++ Polymorphism Virtual Functions Inheritance

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

Lecture Notes Chapter #9_c Abstract Classes & Interfaces

Lecture Notes Chapter #9_c Abstract Classes & Interfaces Lecture Notes Chapter #9_c Abstract Classes & Interfaces Abstract Classes parent class child class more abstract more concrete, i.e., less abstract abstract class o class with an abstract modifier o class

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

Inheritance. Software Engineering with Inheritance. CSC330 Object Oriented Programming. Base Classes and Derived Classes. Class Relationships I

Inheritance. Software Engineering with Inheritance. CSC330 Object Oriented Programming. Base Classes and Derived Classes. Class Relationships I CSC0 Object Oriented Programming Inheritance Software Engineering with Inheritance Can customize derived classes to meet needs by: Creating new member variables Creating new methods Override base-class

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, Polymorphism, and Interfaces Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information

Object Oriented Programming

Object Oriented Programming Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 11 Object Oriented Programming Eng. Mohammed Alokshiya December 16, 2014 Object-oriented

More information

Inheritance (Deitel chapter 9)

Inheritance (Deitel chapter 9) Inheritance (Deitel chapter 9) 1 2 Plan Introduction Superclasses and Subclasses protected Members Constructors and Finalizers in Subclasses Software Engineering with Inheritance 3 Introduction Inheritance

More information

25. Generic Programming

25. Generic Programming 25. Generic Programming Java Fall 2009 Instructor: Dr. Masoud Yaghini Generic Programming Outline Polymorphism and Generic Programming Casting Objects and the instanceof Operator The protected Data and

More information

Chapter 3: Inheritance and Polymorphism

Chapter 3: Inheritance and Polymorphism Chapter 3: Inheritance and Polymorphism Overview Inheritance is when a child class, or a subclass, inherits, or gets, all the data (properties) and methods from the parent class, or superclass. Just like

More information

Object Oriented Programming in C#

Object Oriented Programming in C# Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create

More information

Chapter 6: Inheritance

Chapter 6: Inheritance Chapter 6: Inheritance EECS 1030 moodle.yorku.ca State of an object final int WIDTH = 3; final int HEIGTH = 4; final int WEIGHT = 80; GoldenRectangle rectangle = new GoldenRectangle(WIDTH, HEIGHT, WEIGHT);

More information

We are on the GUI fast track path

We are on the GUI fast track path We are on the GUI fast track path Chapter 13: Exception Handling Skip for now Chapter 14: Abstract Classes and Interfaces Sections 1 9: ActionListener interface Chapter 15: Graphics Skip for now Chapter

More information

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 14 Abstract Classes and Interfaces Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden

More information

COMP 250. inheritance (cont.) interfaces abstract classes

COMP 250. inheritance (cont.) interfaces abstract classes COMP 250 Lecture 31 inheritance (cont.) interfaces abstract classes Nov. 20, 2017 1 https//goo.gl/forms/ymqdaeilt7vxpnzs2 2 class Object boolean equals( Object ) int hashcode( ) String tostring( ) Object

More information

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5, Informatik II Tutorial 6 Mihai Bâce mihai.bace@inf.ethz.ch 05.04.2017 Mihai Bâce April 5, 2017 1 Overview Debriefing Exercise 5 Briefing Exercise 6 Mihai Bâce April 5, 2017 2 U05 Some Hints Variables &

More information

Informatik II (D-ITET) Tutorial 6

Informatik II (D-ITET) Tutorial 6 Informatik II (D-ITET) Tutorial 6 TA: Marian George, E-mail: marian.george@inf.ethz.ch Distributed Systems Group, ETH Zürich Exercise Sheet 5: Solutions and Remarks Variables & Methods beginwithlowercase,

More information

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario The Story So Far... Classes as collections of fields and methods. Methods can access fields, and

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

CMSC 132: Object-Oriented Programming II. Inheritance

CMSC 132: Object-Oriented Programming II. Inheritance CMSC 132: Object-Oriented Programming II Inheritance 1 Mustang vs Model T Ford Mustang Ford Model T 2 Interior: Mustang vs Model T 3 Frame: Mustang vs Model T Mustang Model T 4 Compaq: old and new Price:

More information

Advanced Placement Computer Science. Inheritance and Polymorphism

Advanced Placement Computer Science. Inheritance and Polymorphism Advanced Placement Computer Science Inheritance and Polymorphism What s past is prologue. Don t write it twice write it once and reuse it. Mike Scott The University of Texas at Austin Inheritance, Polymorphism,

More information

Motivations. Objectives. object cannot be created from abstract class. abstract method in abstract class

Motivations. Objectives. object cannot be created from abstract class. abstract method in abstract class Motivations Chapter 13 Abstract Classes and Interfaces You have learned how to write simple programs to create and display GUI components. Can you write the code to respond to user actions, such as clicking

More information

F I N A L E X A M I N A T I O N

F I N A L E X A M I N A T I O N Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student

More information

Chapter 9 - Object-Oriented Programming: Polymorphism

Chapter 9 - Object-Oriented Programming: Polymorphism Chapter 9 - Object-Oriented Programming: Polymorphism Polymorphism Program in the general Introduction Treat objects in same class hierarchy as if all superclass Abstract class Common functionality Makes

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

Chapter 11 Inheritance and Polymorphism

Chapter 11 Inheritance and Polymorphism Chapter 11 Inheritance and Polymorphism 1 Motivations OOP is built on three principles: Encapsulation (classes/objects, discussed in chapters 9 and 10), Inheritance, and Polymorphism. Inheritance: Suppose

More information

Chapter 13 Abstract Classes and Interfaces. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited

Chapter 13 Abstract Classes and Interfaces. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited Chapter 13 Abstract Classes and Interfaces Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations You have learned how to write simple programs

More information

CSC 330 Object-Oriented Programming. Encapsulation

CSC 330 Object-Oriented Programming. Encapsulation CSC 330 Object-Oriented Programming Encapsulation Implementing Data Encapsulation using Properties Use C# properties to provide access to data safely data members should be declared private, with public

More information

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes. a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

More information

Motivations. Chapter 13 Abstract Classes and Interfaces

Motivations. Chapter 13 Abstract Classes and Interfaces Chapter 13 Abstract Classes and Interfaces CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox Motivations You have learned how to write simple

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

Reusing Classes. Hendrik Speleers

Reusing Classes. Hendrik Speleers Hendrik Speleers Overview Composition Inheritance Polymorphism Method overloading vs. overriding Visibility of variables and methods Specification of a contract Abstract classes, interfaces Software development

More information

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance

More information

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance CS257 Computer Science I Kevin Sahr, PhD Lecture 10: Inheritance 1 Object Oriented Features For a programming language to be called object oriented it should support the following features: 1. objects:

More information

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Lecture 36: Cloning Last time: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Today: 1. Project #7 assigned 2. equals reconsidered 3. Copying and cloning 4. Composition 11/27/2006

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Recitation 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University Project 5 Due Wed, Oct. 22 at 10 pm. All questions on the class newsgroup. Make use of lab

More information

What is an interface? Why is an interface useful?

What is an interface? Why is an interface useful? IST311 Interfaces IST311 / 602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition by Y. Daniel Liang 1 What is an interface?

More information

Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal

Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Define and discuss abstract classes Define and discuss abstract methods Introduce polymorphism Much of the information

More information

Final Examination Semester 3 / Year 2010

Final Examination Semester 3 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2010 COURSE : OBJECT-ORIENTED PROGRAMMING COURSE CODE : PROG 2013 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM

More information

Friend Functions, Inheritance

Friend Functions, Inheritance Friend Functions, Inheritance Friend Function Private data member of a class can not be accessed by an object of another class Similarly protected data member function of a class can not be accessed by

More information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance

More information

SSE3052: Embedded Systems Practice

SSE3052: Embedded Systems Practice SSE3052: Embedded Systems Practice Minwoo Ahn minwoo.ahn@csl.skku.edu Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3052: Embedded Systems Practice, Spring 2018, Jinkyu Jeong

More information

CS 1301 Ch 8, Handout 2

CS 1301 Ch 8, Handout 2 CS 1301 Ch 8, Handout 2 This section discusses the split and match methods of the String class, regular expressions, and creating objects from strings, and command line arguments. The split Method 1. The

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

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8 Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg

More information

Industrial Programming

Industrial Programming Industrial Programming Lecture 4: C# Objects & Classes Industrial Programming 1 What is an Object Central to the object-oriented programming paradigm is the notion of an object. Objects are the nouns a

More information

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes What is an Object Industrial Programming Lecture 4: C# Objects & Classes Central to the object-oriented programming paradigm is the notion of an object. Objects are the nouns a person called John Objects

More information

Inheritance -- Introduction

Inheritance -- Introduction Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept

More information

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer Prelim 1 SOLUTION CS 2110, September 29, 2016, 7:30 PM 0 1 2 3 4 5 Total Question Name Loop invariants Recursion OO Short answer Exception handling Max 1 15 15 25 34 10 100 Score Grader 0. Name (1 point)

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 (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming

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 (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes

More information

Polymorphism CSCI 201 Principles of Software Development

Polymorphism CSCI 201 Principles of Software Development Polymorphism CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Program Outline USC CSCI 201L Polymorphism Based on the inheritance hierarchy, an object with a compile-time

More information

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces CS 112 Programming 2 Lecture 10 Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces 2 1 Motivations We have learned how to write simple programs to create and display GUI components.

More information

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. Inheritance Hierarchy. The Idea Behind Inheritance

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. Inheritance Hierarchy. The Idea Behind Inheritance Structural Programming and Data Structures Winter 2000 CMPUT 102: Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection Repetition Vectors

More information

CS 520 Theory and Practice of Software Engineering Fall 2017

CS 520 Theory and Practice of Software Engineering Fall 2017 CS 520 Theory and Practice of Software Engineering Fall 2017 OO design principles September 14, 2017 Today Code review and (re)design of an MVC application OO design principles Information hiding (and

More information

Chapter 13 Abstract Classes and Interfaces

Chapter 13 Abstract Classes and Interfaces Chapter 13 Abstract Classes and Interfaces rights reserved. 1 Motivations You have learned how to write simple programs to create and display GUI components. Can you write the code to respond to user actions,

More information

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. CMPUT 102: Inheritance Dr. Osmar R. Zaïane. University of Alberta 4

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. CMPUT 102: Inheritance Dr. Osmar R. Zaïane. University of Alberta 4 Structural Programming and Data Structures Winter 2000 CMPUT 102: Inheritance Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection Repetition

More information

Inheritance. Chapter 7. Chapter 7 1

Inheritance. Chapter 7. Chapter 7 1 Inheritance Chapter 7 Chapter 7 1 Introduction to Inheritance Inheritance allows us to define a general class and then define more specialized classes simply by adding new details to the more general class

More information

C12a: The Object Superclass and Selected Methods

C12a: The Object Superclass and Selected Methods CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and

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 Interface Abstract data types Version of January 26, 2013 Abstract These lecture notes are meant

More information

Introduction to Inheritance

Introduction to Inheritance Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits

More information

More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014

More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 Object hierarchies Overview Several classes inheriting from same base class Concrete versus abstract classes

More information