Inheritance

Size: px
Start display at page:

Download "Inheritance"

Transcription

1 Inheritance

2 Inheritance Inheritance is the capability of one class to acquire properties and characteristics from another class. For using Inheritance concept in our program we must use at least two classes. The class whose properties are inherited by other class is called the Parent or Base or Super class. And, the class which inherits properties of other class is called Child or Derived or Sub class.

3 Syntax: Class subclass : < access specifier (public, protected, private) > Superclass. class Person { class MathsTeacher : public Person {

4 Access specifiers in Inheritance If access specifier is Public i.e., Class subclass: public Superclass Then the protected member of super class becomes protected members of sub class and public becomes public

5 Access specifiers in Inheritance (Continuation) If access specifier is protected i.e., Class subclass: protected Superclass Then the protected and public members of super class becomes protected members of sub class.

6 Access specifiers in Inheritance (Continuation) If access specifier is private i.e., Class subclass: private Superclass Then the protected and public members of super class becomes private members of sub class.

7 Simple Inheritance program: #include <iostream> using namespace std; // Base class class Shape { protected: int width; int height; public: void setwidth(int w) { width = w; void setheight(int h) { height = h; class Rectangle: public Shape { public: int getarea() { return (width * height); int main(void) { Rectangle Rect; Rect.setWidth(2); Rect.setHeight(2); cout << "Total area: " << Rect.getArea() << endl; return 0;

8 Advantages of Inheritance Inheritance makes the code reusable. When we inherit an existing class, all its methods and fields become available in the new class, hence code is reused. Fast implementation time

9 Types of Inheritance: In C++, we have 5 different types of Inheritance. Namely, 1. Single Inheritance 2. Multiple Inheritance 3. Hierarchical Inheritance 4. Multilevel Inheritance 5. Hybrid Inheritance (also known as Virtual Inheritance)

10 Single Inheritance Single Inheritance: In this type of inheritance one derived class inherits from only one base class. It is the simplest form of Inheritance. Syntax: class derived-class: access-specifier Base-class Class B: public A{

11 Multiple Inheritance: Multiple Inheritance: In this type of inheritance a single derived class may inherit from two or more than two base classes. Syntax: class derived-class: access-specifier basea, access-specifier baseb... Class c: public A, public B{

12 Example for Multiple Inheritance: #include <iostream> using namespace std; class Shape { protected: int width; int height; public: void setwidth(int w) { width = w; void setheight(int h) { height = h; class Rectangle: public Shape, public PaintCost { public: int getarea() { return (width * height); int main(void) { Rectangle Rect; int area; int w,h; cout<<"enter the Widhth and Height \n"; cin>>w>>h; Rect.setWidth(w); Rect.setHeight(h); class PaintCost { public: int getcost(int area) { int cost; cout<<"enter the paint cost for per inches \n"; cin>>cost; return area * cost; area = Rect.getArea(); cout << "Total area: " << Rect.getArea() << endl; cout << "Total paint cost: $" << Rect.getCost(area) << endl; return 0;

13 Hierarchical Inheritance: Hierarchical Inheritance: In this type of inheritance, multiple derived classes inherits from a single base class class A { //content of base class i.e., A class B :public A { //content of derived class i.e., B class C :public A { //content of derived class i.e., C class D :public A { //content of derived class i.e., D

14 Example for Hierarchical Inheritance: #include<iostream> using namespace std; class arithmetic{ protected: int op1,op2; public: void getop(int a, int b){ op1=a; op2=b; int main(){ sum s1; s1.getop(3,4); cout<<"addition is "<<s1.addition(); mul m1; m1.getop(3,4); cout<<"\n Multiplication is "<<m1.multiplication(); return 0; class sum: public arithmetic{ public: int addition(){ return op1+op2; class mul: public arithmetic{ public: int multiplication(){ return op1*op2;

15 Multilevel Inheritance: Multilevel Inheritance: class. class A { a Derived class is a base class for another //content of base class i.e., A class B :public A { //content of class i.e., B class C :public B { //content of derived class i.e., C

16 Example for Multilevel Inheritance: #include<iostream> using namespace std; class person{ protected: int age; char name[10]; public: void getdata(int a, char b[]){ age=a; for(int i=0;i<10;i++) name[i]=b[i]; class student: public person{ protected: char reg[10]; public: void getstu(){ cout<<"\n Enter the Register number :"; cin>>reg; void show(){ cout<<"\n student information \n "; cout<<"name :"<<name<<"\n"; cout<<"age :"<<age<<"\n"; cout<<"rollno :"<<reg<<"\n"; class nitr: public student{ protected: char branch[10]; int y; public: void getcol(){ cout<<"\n Enter the Branch :"; cin>>branch; cout<<"\n Enter the Year :"; cin>>y; void totaldata(){ cout<<"\n student information \n "; cout<<"name :"<<name<<"\n"; cout<<"age :"<<age<<"\n"; cout<<"rollno :"<<reg<<"\n"; cout<<"branch :"<<branch<<"\n"; cout<<"year :"<<y<<"\n";

17 int main(){ nitr p1; int a; char b[10]; cout<<"enter the name "; cin>>b; cout<<"enter the age"; cin>>a; p1.getdata(a,b); p1.getstu(); p1.getcol(); p1.totaldata(); return 0;

18 Hybrid Inheritance: Hybrid Inheritance (also known as Virtual Inheritance): Hybrid Inheritance is combination of Hierarchical and Mutilevel Inheritance. class A { //content of base class i.e., A class B :public A { //content of class i.e., B class C :public B { //content of derived class i.e., C Class D: public B, public C{

19 Try the following Example for hybrid Inheritance class Grandparent { //content of grandparent class class Child1 :public virtual Grandparent { //content of Child1 class class Child2 :public virtual Grandparent { //content of Child2 class class grandson :public Child1, public Child2 { //content of grandson class

20 Assignment 1 (Date: - 9/01/2017) 1. Write a sample C++ program demonstrating Variable scope. 2. Write a C++ program for finding factorial of a given number using recursion. 3. Write a C++ program to find the roots of a quadratic equation. Use switch or if statements to handle different values of the discriminant (b2 4ac). 4. Write a C++ program to create student class, which contains name, Register-Number & 5-subject marks as data members calculate average & grade by using member functions.

21 Assignment 2 (Date: - 16/01/2017) 1. Write a C++ program to calculate area of rectangle and square using constructor (default) and destructor 2. Write a C++ program to calculate area of circle using constructor (parameterized) and destructor 3. Write a C++ program to calculate area of triangle using constructor (copy) and destructor

22 Assignment 3 (Date: - 23/01/2017) Write C++ program to ready student information such as Name, DOB, Address (village/city, district, state and country, pin code), Education details like RegNO, Department, Course (b-tech, m-tech or dual degree) by illustrating following Inheritance concepts. 1. Single Inheritance 2. Multiple Inheritance 3. Hierarchical Inheritance 4. Multilevel Inheritance 5. Hybrid Inheritance (also known as Virtual Inheritance)

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

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I. y UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I Lab Module 7 CLASSES, INHERITANCE AND POLYMORPHISM Department of Media Interactive

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

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

CS OBJECT ORIENTED PROGRAMMING

CS OBJECT ORIENTED PROGRAMMING UNIT-4 INHERITANCE AND RUN TIME POLYMORPHISM Inheritance public, private, and protected derivations multiple inheritance virtual base class abstract class composite objects Runtime polymorphism virtual

More information

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. C++ TEMPLATES http://www.tutorialspoint.com/cplusplus/cpp_templates.htm Copyright tutorialspoint.com Templates are the foundation of generic programming, which involves writing code in a way that is independent

More information

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance. Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit III Inheritance The mechanism that allows us to extend the definition of a class without making

More information

Programming in C++: Assignment Week 6

Programming in C++: Assignment Week 6 Programming in C++: Assignment Week 6 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 6, 2017

More information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++

More information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

INHERITANCE IN OBJECT ORIENTED PROGRAMMING EASIEST WAY TO TEACH AND LEARN INHERITANCE IN C++ TWINKLE PATEL

INHERITANCE IN OBJECT ORIENTED PROGRAMMING EASIEST WAY TO TEACH AND LEARN INHERITANCE IN C++ TWINKLE PATEL International Journal of Computer Science Engineering and Information Technology Research (IJCSEITR) ISSN(P): 2249-6831; ISSN(E): 2249-7943 Vol. 7, Issue 1, Feb 2017, 21-34 TJPRC Pvt. Ltd. INHERITANCE

More information

A A B U n i v e r s i t y

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences 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 Week 10: I n h e r i t a n c e Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

More information

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples: Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before

More information

L4: Inheritance. Inheritance. Chapter 8 and 10 of Budd.

L4: Inheritance. Inheritance. Chapter 8 and 10 of Budd. L4: Inheritance Inheritance Definition Example Other topics: Is A Test, Reasons for Inheritance, C++ vs. Java, Subclasses and Subtypes 7 Forms of Inheritance Discussions Chapter 8 and 10 of Budd. SFDV4001

More information

Midterm Exam 5 April 20, 2015

Midterm Exam 5 April 20, 2015 Midterm Exam 5 April 20, 2015 Name: Section 1: Multiple Choice Questions (24 pts total, 3 pts each) Q1: Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d.

More information

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PROGRAMMING Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PARADIGM Object 2 Object 1 Data Data Function Function Object 3 Data Function 2 WHAT IS A MODEL? A model is an abstraction

More information

CHAPTER 9 INHERITANCE. 9.1 Introduction

CHAPTER 9 INHERITANCE. 9.1 Introduction CHAPTER 9 INHERITANCE 9.1 Introduction Inheritance is the most powerful feature of an object oriented programming language. It is a process of creating new classes called derived classes, from the existing

More information

WWW.STUDENTSFOCUS.COM Unit II OBJECT ORIENTED ASPECTS OF C# Key Concepts of Object Orientation Abstraction Encapsulation Polymorphism Inheritance. Abstraction is the ability to generalize an object as

More information

Developed By Strawberry

Developed By Strawberry Experiment No. 3 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To study below concepts of classes and objects 1. Array of Objects 2. Objects as a function argument 3. Static Members P1: Define a

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

Developed By Strawberry

Developed By Strawberry Experiment No. 7 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To understand the below concept of Inheritance (Part I) 1. Type of inheritance 2. To understand different access specifier. 3. Constructor

More information

UNIT 1 OVERVIEW LECTURE NOTES

UNIT 1 OVERVIEW LECTURE NOTES UNIT 1 OVERVIEW LECTURE NOTES OBJECT-ORIENTED PROGRAMMING IN C++ Object Oriented Programming is a method of visualizing and programming the problem in a global way. Object oriented programming is a technique

More information

C++ Memory Map. A pointer is a variable that holds a memory address, usually the location of another variable in memory.

C++ Memory Map. A pointer is a variable that holds a memory address, usually the location of another variable in memory. Pointer C++ Memory Map Once a program is compiled, C++ creates four logically distinct regions of memory: Code Area : Area to hold the compiled program code Data Area : Area to hold global variables Stack

More information

Developed By Strawberry

Developed By Strawberry Experiment No. 9 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To study virtual functions and Polymorphism P1: Create a base class called 'SHAPE' having - two data members of type double - member

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

Data Structures (INE2011)

Data Structures (INE2011) Data Structures (INE2011) Electronics and Communication Engineering Hanyang University Haewoon Nam ( hnam@hanyang.ac.kr ) Lecture 1 1 Data Structures Data? Songs in a smartphone Photos in a camera Files

More information

Exercise1. // classes first example. #include <iostream> using namespace std; class Rectangle. int width, height; public: void set_values (int,int);

Exercise1. // classes first example. #include <iostream> using namespace std; class Rectangle. int width, height; public: void set_values (int,int); Exercise1 // classes first example class Rectangle int width, height; void set_values (int,int); int area() return width*height; ; void Rectangle::set_values (int x, int y) width = x; height = y; int main

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II Year / Semester: III / V Date: 08.7.17 Duration: 45 Mins

More information

STUDY ON INHERITANCE OF CLASSES

STUDY ON INHERITANCE OF CLASSES STUDY ON INHERITANCE OF CLASSES Pallav Thapa Deaprtment Of Information Technology, Dronacharya College Of Engineering, Gurgaon Abstract-.This paper address about the inheritance in object oriented programming.

More information

International Journal of Advance Research in Computer Science and Management Studies

International Journal of Advance Research in Computer Science and Management Studies Volume 3, Issue 1, January 2015 ISSN: 2321 7782 (Online) International Journal of Advance Research in Computer Science and Management Studies Research Article / Survey Paper / Case Study Available online

More information

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each. I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK 70. a) What is the difference between Hardware and Software? Give one example for each. b) Give two differences between primary and secondary memory.

More information

Inheritance: Single level inheritance:

Inheritance: Single level inheritance: Inheritance: The mechanism of deriving a new class from old one is called inheritance. The old class is referred to as the base class or parent class and the new class is called the derived class or child

More information

Arrays Classes & Methods, Inheritance

Arrays Classes & Methods, Inheritance Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value

More information

CSC1322 Object-Oriented Programming Concepts

CSC1322 Object-Oriented Programming Concepts CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.

More information

Recharge (int, int, int); //constructor declared void disply();

Recharge (int, int, int); //constructor declared void disply(); Constructor and destructors in C++ Constructor Constructor is a special member function of the class which is invoked automatically when new object is created. The purpose of constructor is to initialize

More information

Inheritance and Overloading. Week 11

Inheritance and Overloading. Week 11 Inheritance and Overloading Week 11 1 Inheritance Objects are often defined in terms of hierarchical classes with a base class and one or more levels of classes that inherit from the classes that are above

More information

Sahaj Computer Solutions OOPS WITH C++

Sahaj Computer Solutions OOPS WITH C++ Chapter 6 1 Contents Introduction Types of Inheritances Defining the Derived Class Single Inheritance Making a private data inheritable Multilevel Inheritance Multiple Inheritance Ambiguity Resolution

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class Chapter 6 Inheritance Extending a Class Introduction; Need for Inheritance; Different form of Inheritance; Derived and Base Classes; Inheritance and Access control; Multiple Inheritance Revisited; Multilevel

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

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

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

COMPUTER SCIENCE C++(083) ASSIGNMENT BOOKLET CLASS XII. Academic Session:

COMPUTER SCIENCE C++(083) ASSIGNMENT BOOKLET CLASS XII. Academic Session: COMPUTER SCIENCE C++(083) ASSIGNMENT BOOKLET CLASS XII Academic Session: 2017-18 Computer Science Class XII (C++) Page 1 INDEX Class XII S.No. Topic Page # 1. Month wise breakup of syllabus 3 2. Concepts

More information

Extending Classes (contd.) (Chapter 15) Questions:

Extending Classes (contd.) (Chapter 15) Questions: Extending Classes (contd.) (Chapter 15) Questions: 1 1. The following C++ program compiles without any problems. When run, it even prints out the hello called for in line (B) of main. But subsequently

More information

INHERITANCE - Part 1. CSC 330 OO Software Design 1

INHERITANCE - Part 1. CSC 330 OO Software Design 1 INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1

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

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

Get Unique study materials from

Get Unique study materials from Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code

More information

Constructor - example

Constructor - example Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever

More information

K.Yellaswamy Assistant Professor CMR College of Engineering & Technology

K.Yellaswamy Assistant Professor CMR College of Engineering & Technology UNIT-II Inheritance Inheritance: It creates new classes from existing classes,so that the new classes will aquire all the fetures of the existing classes is called Inheritance. Father and Child relationship

More information

Lecture 6. Inheritance

Lecture 6. Inheritance Inheritance Lecture 6 A key feature of C++ classes is inheritance. Inheritance allows to create classes which are derived from other classes, so that they automatically include some of its "parent's" members,

More information

C++ 프로그래밍실습. Visual Studio Smart Computing Laboratory

C++ 프로그래밍실습. Visual Studio Smart Computing Laboratory C++ 프로그래밍실습 Visual Studio 2015 Contents Inheritance Exercise Practice1 Inheritance Practice 1-1 : Inheritance What is inheritance? The heart of OO programming A mechanism to build a new class by deriving

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

CHAPTER 6 Class-Advanced Concepts - Inheritance

CHAPTER 6 Class-Advanced Concepts - Inheritance CHAPTER 6 Class-Advanced Concepts - Inheritance Page 1 Introduction: The idea of deriving a new class from the existing class. Provides the idea of code reusability. Existing class is called as base class

More information

Syntax to define a Structure: struct structurename { datatype membername1; datatype membername2;... } ; For Example:

Syntax to define a Structure: struct structurename { datatype membername1; datatype membername2;... } ; For Example: STRUCTURE IN C++ 1 A Structure is a collection of variables of different data types under one name. A structure defines a new user defined data type for your current program using which items of different

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

COP 3530 Discussion Session #2 Ferhat Ay

COP 3530 Discussion Session #2 Ferhat Ay COP 3530 Discussion Session #2 Ferhat Ay COP3530-Ferhat Ay-Discussion Ses.#2 1/18/2011 1 Few things about me My name is difficult! Fer-hat, Fur-hot, Far-had, Frad, Fred, Frank, or just say F. I m a PhD

More information

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School Objectives To understand the concepts of modularity and bottom up testing. To be aware of the use of structured

More information

B.Sc. (Hons.) Computer Science I B.Sc. (Hons.) Electronics. (i) Runtime polymorphism and compile time polymorphism

B.Sc. (Hons.) Computer Science I B.Sc. (Hons.) Electronics. (i) Runtime polymorphism and compile time polymorphism [This question paper contains 6 printed pages.] Sr. No. of Question Paper 6065 D Your Roll No.... Unique Paper Code 2341011251305 N arne of the Course Name of the Paper Semester B.Sc. (Hons.) Computer

More information

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

Introduction to Object-Oriented Programming with C++

Introduction to Object-Oriented Programming with C++ Computational Introduction to Object-Oriented ming with C++ 02/19/2009 Outline 1 2 3 4 1 Read Chapter 8 Control logic and iteration 2 s of Section 8.10: Part I, (1) - (11) Due next Tuesday, February 24

More information

C++ Structures Programming Workshop 2 (CSCI 1061U)

C++ Structures Programming Workshop 2 (CSCI 1061U) C++ Structures Programming Workshop 2 (CSCI 1061U) Faisal Qureshi http://faculty.uoit.ca/qureshi University of Ontario Institute of Technology C++ struct struct keyword can be used to define new data types

More information

Use the template below and fill in the areas in Red to complete it.

Use the template below and fill in the areas in Red to complete it. C++ with Inheritance Pproblem involving inheritance. You have to finish completing code that creates a class called shape, from which 3 classes are derived that are called square and triangle. I am giving

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

COMP 249: Object Oriented Programming II. Tutorial 2: Intro to Inheritance

COMP 249: Object Oriented Programming II. Tutorial 2: Intro to Inheritance COMP 249: Object Oriented Programming II Tutorial 2: Intro to Inheritance 1 Overriding Methods Consider the following two classes: public Dog { public void bark() {... public void wagtail() {... public

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

Programming in C++: Assignment Week 5

Programming in C++: Assignment Week 5 Programming in C++: Assignment Week 5 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 3, 2017

More information

SSE2034: System Software Experiment 3 Spring 2016

SSE2034: System Software Experiment 3 Spring 2016 SSE2034: System Software Experiment 3 Spring 2016 Jinkyu Jeong ( jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Object Initialization class Rectangle { private:

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

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

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance?

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance? INHERITANCE - Part 1 OOP Major Capabilities Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors encapsulation

More information

INHERITANCE PART 2. Constructors and Destructors under. Multiple Inheritance. Common Programming Errors. CSC 330 OO Software Design 1

INHERITANCE PART 2. Constructors and Destructors under. Multiple Inheritance. Common Programming Errors. CSC 330 OO Software Design 1 INHERITANCE PART 2 Constructors and Destructors under Inheritance Multiple Inheritance private and protected Inheritance Common Programming Errors CSC 330 OO Software Design 1 What cannot be inherited?

More information

Partha Sarathi Mandal

Partha Sarathi Mandal MA 253: Data Structures Lab with OOP Tutorial 1 http://www.iitg.ernet.in/psm/indexing_ma253/y13/index.html Partha Sarathi Mandal psm@iitg.ernet.in Dept. of Mathematics, IIT Guwahati Reference Books Cormen,

More information

WARM UP LESSONS BARE BASICS

WARM UP LESSONS BARE BASICS WARM UP LESSONS BARE BASICS CONTENTS Common primitive data types for variables... 2 About standard input / output... 2 More on standard output in C standard... 3 Practice Exercise... 6 About Math Expressions

More information

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. Inheritance in Java 1. Inheritance 2. Types of Inheritance 3. Why multiple inheritance is not possible in java in case of class? Inheritance in java is a mechanism in which one object acquires all the

More information

Inheritance and Encapsulation. Amit Gupta

Inheritance and Encapsulation. Amit Gupta Inheritance and Encapsulation Amit Gupta Project 1 How did it go? What did you like about it? What did you not like? What can we do to help? Suggestions Ask questions if you don t understand a concept

More information

Class CSE F. *slides are from CSE S at SKKU & at MIT

Class CSE F. *slides are from CSE S at SKKU & at MIT Class CSE2013-17F *slides are from CSE2013-16S at SKKU & 6.096 at MIT Representing a Vector In the context of geometry, a vector consists of 2 points: a start and a finish Each point itself has an x and

More information

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and 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 20, 2014 Abstract

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

Object Oriented Programming: Inheritance Polymorphism

Object Oriented Programming: Inheritance Polymorphism Object Oriented Programming: Inheritance Polymorphism Shahram Rahatlou Computing Methods in Physics http://www.roma1.infn.it/people/rahatlou/cmp/ Anno Accademico 2018/19 Today s Lecture Introduction to

More information

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

IT101. Inheritance, Encapsulation, Polymorphism and Constructors IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

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

Programming in C++: Programming Test-2

Programming in C++: Programming Test-2 Programming in C++: Programming Test-2 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 20,

More information

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

More information

22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs.

22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs. Scheme I Sample Question Paper Program Name : Computer Engineering Program Group Program Code : CO/CM/IF/CW Semester : Third 22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time:

More information

Exception with arguments

Exception with arguments Exception Handling Introduction : Fundamental Syntax for Exception Handling code : try catch throw Multiple exceptions Exception with arguments Introduction Exception: An abnormal condition that arises

More information

END TERM EXAMINATION

END TERM EXAMINATION END TERM EXAMINATION THIRD SEMESTER [BCA] DECEMBER 2007 Paper Code: BCA 209 Subject: Object Oriented Programming Time: 3 hours Maximum Marks: 75 Note: Attempt all questions. Internal choice is indicated.

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

Review Questions for Final Exam

Review Questions for Final Exam CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.

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

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What

More information

Laboratory 7. Programming Workshop 2 (CSCI 1061U) Faisal Qureshi.

Laboratory 7. Programming Workshop 2 (CSCI 1061U) Faisal Qureshi. Laboratory 7 Programming Workshop 2 (CSCI 1061U) Faisal Qureshi http://faculty.uoit.ca/qureshi C++ Inheritance Due back on Saturday, March 25 before 11:59 pm. Goal You are asked to create a commandline-based

More information

Classes and Data Abstraction: struct

Classes and Data Abstraction: struct Classes and Data Abstraction: struct There are many instances in programming where we need more than one variable in order to represent an object. For example, to represent yourself, you might want to

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

Procedural Programming

Procedural Programming Procedural Programming Data is stored in variables - Perhaps using arrays and structs. Program is a collection of functions that perform operations over the variables - Good example: electronics inventory

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

C++ Inheritance. Dr. Md. Humayun Kabir CSE Department, BUET

C++ Inheritance. Dr. Md. Humayun Kabir CSE Department, BUET C++ Inheritance Dr. Md. Humayun Kabir CSE Department, BUET C++ Inheritance Inheritance allows one object to inherit member variables and/or member functions from another object. Inherited object is called

More information