Inheritance Ch

Similar documents
QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

QUIZ. How could we disable the automatic creation of copyconstructors

Lecturer: William W.Y. Hsu. Programming Languages

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)

And Even More and More C++ Fundamentals of Computer Science

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Object Oriented Programming COP3330 / CGS5409

Classes Ch

Dynamic memory in class Ch 9, 11.4, 13.1 & Appendix F

C++ Important Questions with Answers

Data Abstraction. Hwansoo Han

Ch02. True/False Indicate whether the statement is true or false.

Classes Nov 3, Ch

Late binding Ch 15.3

HOW TO CONFIGURE SOCIAL MEDIA PRIVACY SETTINGS

CS Lecture #6. Administrative... Assignment #2 Graded NN Turned In, Average Grade: XX Assignment #3 due on Thursday

Data Structures and Other Objects Using C++

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Chapter 10 :: Data Abstraction and Object Orientation

QUIZ. What is wrong with this code that uses default arguments?

What is Realm? Realm is here!

Chapter 9 :: Data Abstraction and Object Orientation

Late binding Ch 15.3

Bonzi Team 101 (Youth Sports): What does Bonzi Team do?

And Even More and More C++ Fundamentals of Computer Science

Survey #2. Programming Assignment 3. Final Exam. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

QUIZ Friends class Y;

accordingly. This is managed through our Other content feature.

Derived Classes in C++

PROGRESS BOOK PARENT ACCESS NAVIGATION

Inheritance and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees

CSE 12 Abstract Syntax Trees

CHAPTER 9 INHERITANCE. 9.1 Introduction

Genome 559 Intro to Statistical and Computational Genomics Lecture 15b: Classes and Objects, II Larry Ruzzo

COP 3530 Discussion Session #2 Ferhat Ay

FAQs. A guide for school app administrators

AOL keyword: UPGRADE HELP = This keyword will give you much information about how to install or upgrade to a higher version of AOL.

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

public Twix() { calories = 285; ingredients = "chocolate, sugar, cookie, caramel"; }

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Previous Capstone Project

Chapter 15: Inheritance, Polymorphism, and Virtual Functions

CS-202 Introduction to Object Oriented Programming

CIO 24/7 Podcast: Tapping into Accenture s rich content with a new search capability

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I.

Getting Started with StrategyBlocks. Training Guide StrategyBlocks 4.0

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees

Lecture 15: Object-Oriented Programming

Python Class Definition. Java Class Definition. Python Class Use public class Student { Java Class Use. Python Class Definition 10/6/2016

Chapter 3: Inheritance and Polymorphism

C++ Classes & Object Oriented Programming

Inheritance (an intuitive description)

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

CS61B Lecture #13: Packages, Access, Etc.

Chapter 2. Building Multitier Programs with Classes The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

The Stack, Free Store, and Global Namespace

G Programming Languages - Fall 2012

Edmodo for Teachers Guide (Taken directly from Edmodo s site.)

VIRTUAL FUNCTIONS Chapter 10

Software Design and Analysis for Engineers

LEARN JAVASCRIPT VISUALLY BY IVELIN DEMIROV DOWNLOAD EBOOK : LEARN JAVASCRIPT VISUALLY BY IVELIN DEMIROV PDF

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CMSC202 Computer Science II for Majors

XII- COMPUTER SCIENCE VOL-II MODEL TEST I

CSE 326: Data Structures Splay Trees. James Fogarty Autumn 2007 Lecture 10

CSE 303: Concepts and Tools for Software Development

JAVA MOCK TEST JAVA MOCK TEST II

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7

Activity Guide - Public Key Cryptography

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

Things You Will Most Likely Want to Do in TeamSnap

Homework 2 Implementing the University Application Due: November 7, 2004 (Sunday midnight)

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I

DRX Your School Lunch Payment Program

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Java Programming. Manuel Oriol, March 22nd, 2007

Inheritance and Polymorphism

CMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019

Binary Files Ch 11.3

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

Ruby II. Classes. Classes are straight forward in Ruby.

Survey #2. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

COMP 2355 Introduction to Systems Programming

Chapter 14. Inheritance. Slide 1

M275 - Web Development using PHP and MySQL

More loops Ch

Gateways can be thought of as Institutional Space the place where assets can be published from a user s Personal Space for viewing by other users.

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

Creating an account on Arbiter Athlete for STUDENTS

CSC207 Week 3. Larry Zhang

Chapter 14 Inheritance. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Transcription:

Inheritance Ch 15.1-15.2

Announcements Test graded!

Highlights - Creating parent/child classes (inheritance) -protected

Story time

Story time

Story time

Story time

Story time

Derived classes Let's make this story into code! To create create a child class from a parent class, use a : in the (child) class declaration child class (See: dunecat.cpp) parent class

Derived classes In a parent/child class relationship, the child gets all variables and functions of the parent This allows you to build off previous work, even if you need to modify it slightly This also makes it easier to maintain code, as changing it in the parent class can effect all children (and the children's children)

Derived classes Typically you use classes when you have multiple objects that are somewhat similar You group the similar parts into a parent class and the different parts into children classes For examples all chairs have a flat surface to sit on, but they come in different designs (folding types that you are sitting on) (or rolling types)

Derived classes Parent: (Internal combustion engine) Children:

Phone

Finding similarities Consider these two sports: If you were going to create a C++ class for these, what data would you store in them?

Finding similarities Consider two classes you have made already: Point Complex You can have a single parent of both of these that stores the similar parts This means you only need to type the code once for both classes (See: complexpoint.cpp)

Types + inheritance What type of object is soccer? It is (obviously) a soccer, but could it also be classified as sports? In fact, yes... both of these are legal: soccer have more functionality than sports (extra stuff), so they can act as one (just pretend some boxes aren't there)

Types + inheritance The reverse is not true (as we are using them): You cannot say: As the worldcup variable has more info than the fun variable (the computer refuses to just guess at the missing functions/data) (see: convertclasstypes.cpp)

Break!

Constructors + inheritance Constructors need to be run every time you make an object... Now that objects have multiple types what constructors are being run? Both actually (again) (See: computerconstructor.cpp)

Constructors + inheritance If you do not specify what constructor to use, it will use the default constructor (or give an error if this does not exist) You can also specify a non-default constructor by using a : after the child's constructor (See: computerconstructorv2.cpp)

protected We know about two scopes for variables: 1. public (anyone, anywhere can use) 2. private (only my class can use) But there is a third: 3. protected (me or my children can use) If you think your children will modify/use a variable, make it protected (See: classscopes.cpp)

protected Picture: Red = private Green = protected Blue = public Variables should be either private or protected Parent Child main()

protected While children technically inherit the private variables/functions, they cannot use them So effectively, they do not inherit these It is not considered bad practice to make variables protected (unlike public) Does access matter? Yes, because computer viruses

Redefine functions As children add functionality to a parent class, they may want to redefine some functions This is different than overloading, where you create multiple versions with the same name When you redefine, you are basically replacing an old function with a new version (See: computerredefine.cpp)

Redefine functions After you have redefined a function, the default name will go to the child's version However, you can still access the parent's version by using :: (class affiliation)

Not inherited As we saw before, constructors are not really inherited (though they are called) overloading operators will also not be inherited (as computer cannot convert parent into child class) Destructors are also not inherited, but the parent's version of the destructor will always run (See: childdestructor.cpp)