Eighth step for Learning C++ Programming

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Operator overloading redefine the operations of operators
Programming Methodology (1). Implementing Methods main.
Operator Overloading. Introduction Operator overloading –Enabling C++’s operators to work with class objects –Using traditional operators with user-defined.
CMSC 202, Version 2/02 1 Operator Overloading Strong Suggestion: Go over the Array class example in Section 8.8 of your text. (You may ignore the Array.
March 25, 2014CS410 – Software Engineering Lecture #12: Advanced C++ I 1 Alumni Party The Alumni Party will take place on Tuesday, May 13 It would be great.
Chapter 1 Inheritance University Of Ha’il.
EC-241 Object-Oriented Programming
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
C++ data types. Structs vs. Classes C++ Classes.
Inheritance, Polymorphism, and Virtual Functions
Lecture From Chapter 6 & /8/10 1 Method of Classes.
Inheritance #1 First questions Similar to Python? What about visibility and encapsulation? – can an object of the child class access private members.
CSE 333 – SECTION 4. Overview Pointers vs. references Const Classes, constructors, new, delete, etc. More operator overloading.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
CMSC 202 Lesson 12 Operator Overloading II. Warmup  Overload the + operator to add a Passenger to a Car: class Car { public: // some methods private:
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Operator Overloading Operator Overloading allows a programmer to define new types from the built-in types. –Operator Overloading is useful for redefining.
Chapter 10 Inheritance and Polymorphism
Topic 1 11/18/2015. Submitted By: Arslan Ali : Roll No: 6703 Ali Ahmad : Roll No: 6710 Ameer Moavia : Roll No: 6734 Abdul Manam : Roll No: 6738 Agha Waqas.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Session 04 Module 8: Abstract classes and Interface Module 9: Properties and Indexers.
Inheritance, Polymorphism, And Virtual Functions Chapter 15.
What Is Inheritance? Provides a way to create a new class from an existing class New class can replace or extend functionality of existing class Can be.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
Bayu Priyambadha, S.Kom. * Poly = Many, Morph = form * Polymorphism refers to a principle in biology in which an organism or species can have many different.
10 Polymorphism. 2 Contents Defining Polymorphism Method Overloading Method Overriding Early Binding and Late Binding Implementing Polymorphism.
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
Polymorphism CMPS Poly-morphism Means “many-forms” Means different things in biology, chemistry, computer science Means different things to functional.
Overloading Methods In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Classes Sujana Jyothi C++ Workshop Day 2. A class in C++ is an encapsulation of data members and functions that manipulate the data. A class is a mechanism.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Lecture 12 Implementation Issues with Polymorphism.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Inheritance and Polymorphism
Operator Overloading Part 2
Inheritance, Polymorphism, and Virtual Functions
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Templates.
Object Oriented Analysis and Design
Lab 02 - SNAP.
OOP’S Concepts in C#.Net
Overloading the << operator
Function Overloading C++ allows us to define functions that have the same name but different sets of parameters This capability can be used to define similar.
Inheritance, Polymorphism, and Virtual Functions
IS437: Fall 2004 Instructor: Dr. Boris Jukic
Object-Oriented Programming
METHOD OVERRIDING in JAVA
Method Overriding in Java
By Muhammad Waris Zargar
Object-Oriented Programming (OOP) Lecture No. 25
Method of Classes Chapter 7, page 155 Lecture /4/6.
Inheritance and Polymorphism
CIS 199 Final Review.
C++ Programming CLASS This pointer Static Class Friend Class
Constructor, Destructor Mehroz Sadiq CS Faculty, UMT Department of CS&E, UET.
Classes and Objects CGS3416 Spring 2019.
Overloading the << operator
C++ data types.
Programming in C# CHAPTER 5 & 6
Presentation transcript:

Eighth step for Learning C++ Programming CLASS Friend Overloading vs Overriding Protected Polymorphism

A Class can declare other classes as "friend classes". Friends A Class can declare other classes as "friend classes". A Class can declare external functions as "friends". friends can access private members and methods. 11/2014

friend int printfoo( foo &f1); }; Friend Declaration class foo { private: int i,j; … friend class fee; friend int printfoo( foo &f1); }; 11/2014

[ practice 1 Friend ]

[ explain 1 Friend ]

Overloading vs Overriding - allows creating several methods with the same name which differ from each other in the type of the input and the output of the function. Polymorphism way. Overriding - allows a child class to provide a specific implementation of a method that is already provided by one of its parent classes Overloading Overriding method name same type or number of parameter different return type same or different class C { public : void test(int a); void test(char b); } class D : public C { public : void test(int a); int test(int a); }

[ practice 2 method overriding (1/2) ]

[ practice 2 method overriding (2/2) ]

[ explain 2 method overriding ]

[ practice 3 Overriding & Overloading ]

[ explain 3 Overriding & Overloading ]

[ practice 4 Protected (1/2) ]

[ practice 4 Protected (2/2) ]

[ explain 4 Protected ]