Object Oriented Programming CS250

Size: px
Start display at page:

Download "Object Oriented Programming CS250"

Transcription

1 Object Oriented Programming CS250 Abas Computer Science Dept, Faculty of Computers & Informatics, Zagazig University

2 Polymorphism Chapter 8

3 8.1 Static and Dynamic Binding Static binding means that the address of an object is known at compile time. A statically bound function's address is known at compile time. Dynamic binding means that a single pointer can point to objects of different types. C++ permits dynamic binding, where a pointer or reference can address objects of different types as long as their classes are related by inheritance. A dynamically bound function must have its address looked up at run time. A call to a statically bound function results in faster execution than a call to a dynamically bound one.

4 8.2 Defining Polymorphism polymorphism is defined as the concept where a single name may denote objects of different classes that are related by some common base class. To implement polymorphism, a language must support dynamic binding. Polymorphism is so useful because it allows the programmer to manipulate instances of derived classes through a set of operations defined in their base class. Each derived class can implement the operations defined in the base class differently, while retaining a common class interface provided by the base class.

5 For example, let us assume that the SalariedEmployee class is derived from Employee, and that both classes contain a CalcPaycheck member function. CalcPaycheck is a simple example of the "common class interface": class Employee { public: void CalcPaycheck(); //... } ; class SalariedEmployee :public Employee { public: void CalcPaycheck(); //... };

6 Next, let's declare ep as an Employee pointer and assign it the address of a SalariedEmployee object. Employee * ep; ep = new SalariedEmployee; ep->calcpaycheck(); The CalcPaycheck function in the Employee class is called. In order to cause the CalcPaycheck function in the SalariedEmployee class to be called, CalcPaycheck function should be declared as a virtual function in the Employee class.

7 8.3 Virtual Function A virtual function is a nonstatic member function prefaced by the virtual specifier. It tells the compiler to generate code that looks up an object's type at runtime and uses this information to select the appropriate version of the function. For example, consider the CalcPaycheck function from the previous example: If the program somehow "knew" that ep pointed to a SalariedEmployee, it could have called the CalcPaycheck function in the SalariedEmployee class.

8 A virtual function may optionally be overridden by functions in derived classes having the same signature. The virtual specifier needs only to appear with the base class function. But it's a good idea to duplicate the virtual specifier in the derived classes as well. For example, let's suppose that both the SalariedEmployee and HourlyEmployee classes are derived from Employee:

9 class Employee { public: virtual void CalcPaycheck(); }; class HourlyEmployee :public Employee { public: virtual void CalcPaycheck(); }; class SalariedEmployee :public Employee { public: virtual void CalcPaycheck(); }; Employee *p0 = new Employee; Employee *p1 = new SalariedEmployee; Employee *p2 = new HourlyEmployee; P0->Calcpaycheck(); // calls Employee::CalcPaycheck() pl->calcpaycheck(); // calls SalariedEmployee::CalcPaycheck() p2->calcpaycheck(); // calls HourlyEmployee::CalcPaycheck()

10 Any nonstatic member function except a constructor can be virtual. Virtual functions can also be friends of other classes. Some compilers require the class destructor to be virtual if a class contains any virtual functions.

11 8.4 Combinations of Virtual and Non-Virtual Functions What if a non-virtual function calls a virtual function? For example, we can define the Employee and SalariedEmployee classes as follows: class Employee { public: void Display() const; // non-virtual virtual void Calcpaycheck(); // virtual }; class SalariedEmployee :public Employee { public: void Display() const; virtual void CalcPaycheck(); };

12 void Employee::Display(){ Calcpaycheck(); } void SalariedEmployee::Display() { CalcPaycheck(); } We invoke Display through the pointer ep. Employee *ep = new SalariedEmployee; ep->display( ) ; This causes Employee::Display() to be called, which in turn calls SalariedEmployee::CalcPaycheck(). In other words, CalcPaycheck() still works as a virtual function, although it is called by a non-virtual function.

13 What if a virtual function calls a non-virtual function? For example: class Employee { public: virtual void Display() const; // virtual void CalcPaycheck(); // non-virtual }; class SalariedEmployee :public Employee { public: virtual void Display() const; void CalcPaycheck(); }; Employee *ep = new SalariedErnployee; ep->display(); This causes SalariedEmployee::Display() to be called, which in turn calls SalariedEmployee::CalcPaycheck():

14 8.5 A Common Interface Virtual functions in a base class provide a common interface for all of its derived classes. In the Employee class, for example, we might want to define a general set of operations that get and set data member values, display an Employee, input an Employee, and process an Employee's paycheck: class Employee { public: long GetDepartment()const; long GetId() const; void SetDepartment(long deptid); void SetId(); virtual void CalcPaycheck() const; virtual void Input(); virtual void CalcPaycheck(); private: long id; long deptnum; };

15 Member functions that should be virtual are those functions that will be implemented in derived classes. GetId(), for example, is not virtual because it only refers to a private data member. CalcPaycheck, on the other hand, is implemented differently for each type of Employee, including those paid a monthly salary and those paid on an hourly basis.

16 8.6 Passing Objects by Address Virtual functions are also useful when a function parameter's type is a pointer or reference to a base class. When calling the function, we can pass a pointer or reference to an object that is of any type derived from the base class. For example: void ProcessAnyEmployee( Employee & er ) { long anid = er.getid(); // non-virtual er.calcpaycheck() ; // virtual }

17 Since the CalcPaycheck () is a virtual function, the particular instance of CalcPaycheck() to be called is determined at run time. Since the GetId () is not a virtual function, it will be called directly from the Employee class. Because C++ supports polymorphism, a programmer can pass an Employee, a SalariedEmployee, or any other type derived from Employee to the ProcessAnyEmployee () function.

18 This offers the advantage of writing a single function that handles all types of employees: For example: SalariedEmployee S; HourlyEmployee H; / /... ProcessAnyEmployee( S ); ProcessAnyEmployee( H );

19 The effect is the same if ProcessAnyEmployee() has an Employee * parameter: void ProcessAnyEmployee( Employee * ep ) { long anid = ep->getid(); // non-virtual ep->calcpaycheck(); // virtual } SalariedEmployee S; HourlyEmployee H; //... ProcessAnyEmployee( &S ); ProcessAnyEmployee( &H );

20 8.7 Virtual Destructors A virtual destructor is preceded by the virtual specifier and behaves like a virtual function. If we assume that a base class and one or more of its derived classes have destructors. we must make sure that the correct destructor is called for a base pointer that currently points to a derived object. Calling the wrong destructor could be disastrous. Particularly when it contains a delete statement: the wrong size chunk of memory might be deallocated. For this reason, we recommend that any class containing virtual functions should also have a virtual destructor.

21 In the next example, the BookItem class is derived from Item class and we have a pointer in BookItem that must be deallocated: class Item { public: virtual ~Item(); //. }; class BookItem :public Item { public: virtual ~BookItem(); private: char *title; }; Item *p; // base pointer p = new BookItem; // point to derived object delete p; // calls the BookItem destructor

22 By making the destructors virtual, we ensure that the BookItem destructor is called when we apply the delete operator to p. Destructors are not inherited, so it is wise to define one for each derived class. In our example, if we omitted the destructor from BookItem, a default destructor would automatically be created for the class, but it would not contain statements to deallocate storage pointed to by class data members.

23 8.8 Abstract Classes An abstract class is a class that can only be a base class for other classes. You cannot create an instance of an abstract class. Instead, it serves as a base for other classes, containing operations that are common to all of its derived classes. An abstract class either contains or inherits at least one pure virtual function. A pure virtual function is a virtual function that contains a pure-specifier, designated by the "= 0" following the function prototype:

24 class Shape { public: virtual void Draw() = 0; }; A pure virtual function is not implemented in the base class, but it serves as a prototype for derived classes that implement the function. In fact, a derived class must implement all pure virtual functions declared in its base class if instances of the derived class are to be created; otherwise, the derived class is automatically an abstract class.

25 Consider the case of the SalariedEmployee and HourlyEmployee classes. We already know that certain operations are common to both classes, such as Display, Input, and CalcPaycheck. We create an abstract class called Employee containing pure virtual member functions: class Employee { public: virtual void Display() = 0; virtual void Input() = 0; virtual void CalcPaycheck() = 0; // };

26 We would probably derive a number of different classes from Employee. Each of those classes would share the common interface defined here. Also, to be sure that the derived classes do not duplicate the same operations in Employee using different function names, we force those classes to override the pure virtual functions and implement the operations. Abstract classes are an ideal vehicle for presenting a class interface without letting users see the class implementation. One might decide not to place any private members in an abstract class. Only operations that comprise the interface would be described in the header file for the abstract class.

27 8.9 Shape Class Example The following Shape abstract class includes three operations, Draw, MoveTo, and Rotate, which are common to its derived classes: class Shape { public: }; virtual ~Shape() ; virtual void Draw() const = 0; virtual void MoveTo( int x2, int y2 ) = 0; virtual void Rotate(int degrees) = 0;

28 The Circle class, derived from Shape, must override each of the pure virtual functions, or it too will be considered an abstract class: class Circle: public Shape { public: Circle() ; Circle(const Point & acenter, float aradius ); virtual ~Circle(); virtual void Draw() const; virtual void MoveTo( int x2. int y2 ); virtual void Rotate{ int degrees ); private: Point center; float radius; };

29 The Polygon class, on the other hand, is an abstract class because we have not implemented all of the pure virtual functions from the Shape class: class Polygon :public Shape { public: Polygon() ; Polygon ( Point & cent, Point * verts }; virtual ~Polygon(); private: Point center; Point * vertices; // array of Points };

30 Pure virtual functions provide a good mechanism to prevent the inadvertent omission of a essential operations in derived classes. If we tried, for example, to create an instance of Circle, and if Circle did not contain a Rotate function, the compiler would issue an error saying that it could not create an instance of an abstract class.

31 8.10 Exception Handling Exception handling is a sophisticated way to handle runtime errors in C++. Rather than aborting a program and leaving objects in an undefined (or corrupted) state, exception handling gives us the ability to perform a more graceful recovery from errors. Exception handling lets us handle an error at different levels, providing context-specific information that can be used as an aid to fixing the problem that caused the exception.

32 In C++, errors such as memory exhaustion, subscript range errors, or division by zero are called exceptions. The range and definition of these errors, as well as the way the errors are handled, can be programmer-defined. In C++, when an exception is generated, the error cannot be ignored or the program will terminate.

33 If error handling code is in place for a particular type of error, the program has the option of recovering from the error and continuing execution. A program throws an exception at the point where an error is first detected. When this happens, a C++ program automatically searches for a block of code called an exception handler, which responds to the exception in some appropriate way. This response is called catching an exception. If an exception handler cannot be found, the program simply terminates.

34 Throw, Catch, and Try Many different types of exceptions can occur, so when an exception is thrown, a throw expression (or throw point) identifies the type of exception. Example: the following throws an exception when a subscript is out of bounds: const unsigned ArraySize = 500; unsigned i; if( i >= ArraySize ) // subscript valid? throw RangeError(); // no: throw an exception

35 RangeError is not a standard exception class, so it must be defined within the current scope. This version of RangeError has no data or function members, but other exeception classes often do: class RangeError{ }; // exception class

36 The try keyword, along with statements falling within { } braces is called a try block. It must be immediately followed by one or more exception handlers. Each exception handler begins with the catch keyword, followed by a block containing statements. The following shows the format of a try block followed by two handlers: try { statement-list } catch ( parameter-list){ statement-list } catch ( parameter-list){ statement-list }

37 The most likely parameter is an exception object, usually passed by constant reference, such as: const RangeError & R. An exception can only be thrown after a program's execution has entered a try block. The throw expression might be physically inside the block, or it might be nested in functions called from the try block. In the next example, TestTheArray calls InsertValue from a try block. Inside InsertValue, if i is too large, a RangeError exception is thrown and control immediately passes to the handler in TestTheArray. An error message is displayed and the program continues without having corrupted memory with an out-of-range subscript: const unsigned ArraySize = 50; int array[arraysize]; //

38 void InsertValue( unsigned i, int value){ if( i >= ArraySize ) throw RangeError(); array[i] = value; } void TestTheArray(){ unsigned j; int anint; cout «"Enter a subscript and a value: "; cin» j» anint; try { InsertValue( j, anint ); } catch( const RangeError & ) { cout «"Range error in TestTheArray()"; throw; }}

39 In this example, the handler throws the same exception object backward to the previous context, which is the function that called TestTheArray. This re-throwing of the exception is optional, but helpful when the program must back up through nested function calls, possibly all the way to main. When an exception is thrown, a C++ program backs up all the way to main until a handler is found, or the program terminates.

40 Unwinding the Execution Stack When a program throws an exception, the destructor is called for each object that was constructed from the time the program entered a try block. This process is called stack unwinding, and it is a major strength of the exception handling mechanism. Example: if an exception is thrown while creating the LongArray object, the file stream's destructor is called first, then the handler executes: try { ofstream log("log.txt"); LongArray L(30000); } catch( xalloc ){ cout «"Unable to create LongArray"; }

41 When an exception is thrown during the construction of a composite object, destructors will be invoked only for those data members that have already been constructed. Similarly, if an exception is thrown during the construction of an array of objects, destructors are invoked only for those array elements that have already been constructed. Example: the Student class contains VString and Transcript data members. The student's name will be constructed first, followed by the records data member: class VString {...}; class Transcript { }; class Student { private: VString lastname; Transcript records; };

42 int main ( ) { try { VString collegename("computers & Infomatics"); Student S; } catch (... ) { / /... } assume that an exception is thrown by the Transcript constructor. First, the VString destructor is invoked for collegename, Followed by the same destructor for S.lastName. But the Transcript destructor is not invoked because the records data member was only partially constructed.

43 If an exception is thrown again while a destructor is executing, terminate is called. Also, if a handler cannot be found for a thrown exception, terminate is called. when terminate is called, standard C++ does not specify whether or not the stack is unwound, so destructors for existing class objects might not be called.

44 8.11 Debugging Tips Avoiding Calls to new in User Code Consistent with block scope rules, any object declared in a try block is not accessible outside the block. This creates an interesting problem when statements within a try block perform memory allocation.

45 Example: if the first array of characters is successfully allocated but the second array allocation fails, pc1 goes out of scope without letting us deallocate the memory it addresses: const unsigned size1 = 500; const unsigned size2 = 30000; try { char *pc1 = new char[size1]; char *pc2 = new char[size2]; } catch ( xalloc ){ cout «"Allocation error"; }

46 To prevent this type of problem, we can avoid directly calling the new operator in user code. Wrap all memory allocations inside classes. So whenever an exception is thrown, each object's destructor takes care of its own memory deallocation.

47 rewrite the foregoing example, this time using DynString objects to hold the two character arrays. In a test run of the program, object pc1 was allocated successfully, but pc2 was not. The output from the program was Created string at: 0x0dc2 Deleted string at: 0x0dc2 Allocation error caught. By comparing the program to its output, we see that an exception was thrown while attempting to allocate pc2, so the destructor for pc1 was called. Finally, the handler was executed.

48 #include <iostream.h> #include <except.h> const unsigned size1 = 500; const unsigned size2 = 30000; class DynString{ public: DynString(unsigned strsize); ~DynString(); private: char *str; unsigned size; }; DynString:: DynString(unsigned strsize){ size=strsize; str=new char[strsize]; cout<< Created string at: <<hex<<&str<<endl; }

49 DynString::~ DynString(){ delete [] str; cout<< Deleted string at: <<hex<<&str<<endl; } int main(){ try { DynString pc1(size1); DynString pc2(size2); cout<< Both allocations successful \n ; } catch(xalloc){ cout<< Allocation error caught. ; } return 0; }

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

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

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 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 adult

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

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Short Notes of CS201

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

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

CS201 - Introduction to Programming Glossary By

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

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 6 : Abstraction Lecture Contents 2 Abstract classes Abstract methods Case study: Polymorphic processing Sealed methods & classes

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Written by John Bell for CS 342, Spring 2018

Written by John Bell for CS 342, Spring 2018 Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

! Errors can be dealt with at place error occurs

! Errors can be dealt with at place error occurs UCLA Stat 1D Statistical Computing and Visualization in C++ Instructor: Ivo Dinov, Asst. Prof. in Statistics / Neurology University of California, Los Angeles, Winter 200 http://www.stat.ucla.edu/~dinov/courses_students.html

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

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

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2 Review Fall 2013 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2013 CISC2200 Yanjun Li 2 1 Array Arrays are data structures containing related data items of same type. An

More information

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2

Review. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2 Review Fall 2017 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2017 CISC2200 Yanjun Li 2 1 Computer Fall 2017 CISC2200 Yanjun Li 3 Array Arrays are data structures containing

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance

More information

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103

More information

CGS 2405 Advanced Programming with C++ Course Justification

CGS 2405 Advanced Programming with C++ Course Justification Course Justification This course is the second C++ computer programming course in the Computer Science Associate in Arts degree program. This course is required for an Associate in Arts Computer Science

More information

More C++ : Vectors, Classes, Inheritance, Templates

More C++ : Vectors, Classes, Inheritance, Templates Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit

More information

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

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

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 12 continue 12.6 Case Study: Payroll System Using Polymorphism This section reexamines the CommissionEmployee- BasePlusCommissionEmployee hierarchy that we explored throughout

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

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

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes

More information

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

Extending Classes (contd.) (Chapter 15) Questions: Extending Classes (contd.) (Chapter 15) Questions: 1 Virtual Functions in C++ Employee /\ / \ ---- Manager 2 Case 1: class Employee { string firstname, lastname; //... Employee( string fnam, string lnam

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 Introduction 2 IS 0020 Program Design and Software Tools Exception Handling Lecture 12 November 23, 200 Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually

More information

void fun() C::C() // ctor try try try : member( ) catch (const E& e) { catch (const E& e) { catch (const E& e) {

void fun() C::C() // ctor try try try : member( ) catch (const E& e) { catch (const E& e) { catch (const E& e) { TDDD38 APiC++ Exception Handling 134 Exception handling provides a way to transfer control and information from a point in the execution to an exception handler a handler can be invoked by a throw expression

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

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1 CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining

More information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Midterm Review. PIC 10B Spring 2018

Midterm Review. PIC 10B Spring 2018 Midterm Review PIC 10B Spring 2018 Q1 What is size t and when should it be used? A1 size t is an unsigned integer type used for indexing containers and holding the size of a container. It is guarenteed

More information

C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15

C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15 C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15 This chapter introduces the notion of dynamic memory allocation of variables and objects in a C++ program.

More information

Polymorphism. Arizona State University 1

Polymorphism. Arizona State University 1 Polymorphism CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 15 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

OOP THROUGH C++(R16) int *x; float *f; char *c;

OOP THROUGH C++(R16) int *x; float *f; char *c; What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,

More information

04-24/26 Discussion Notes

04-24/26 Discussion Notes 04-24/26 Discussion Notes PIC 10B Spring 2018 1 When const references should be used and should not be used 1.1 Parameters to constructors We ve already seen code like the following 1 int add10 ( int x

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

More information

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a. Intro to OOP - Object and class - The sequence to define and use a class in a program - How/when to use scope resolution operator - How/when to the dot operator - Should be able to write the prototype

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name

More information

Introduction. Common examples of exceptions

Introduction. Common examples of exceptions Exception Handling Introduction Common examples of exceptions Failure of new to obtain memory Out-of-bounds array subscript Division by zero Invalid function parameters Programs with exception handling

More information

Instantiation of Template class

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

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba Exception handling Exception an indication of a problem that occurs during a program s execution. The name exception implies that the problem occurs infrequently. With exception

More information

mywbut.com Exception Handling

mywbut.com Exception Handling Exception Handling An exception is a run-time error. Proper handling of exceptions is an important programming issue. This is because exceptions can and do happen in practice and programs are generally

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

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

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Section 1 Multiple Choice Questions (40 pts total, 2 pts each): Q1: Employee is a base class and HourlyWorker is a derived class, with

More information

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

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

More information

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

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY Pages 800 to 809 Anna Rakitianskaia, University of Pretoria STATIC ARRAYS So far, we have only used static arrays The size of a static array must

More information

Inheritance, Polymorphism and the Object Memory Model

Inheritance, Polymorphism and the Object Memory Model Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation

More information

POINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory

More information

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++ Introduction to Programming in C++ Course Text Programming in C++, Zyante, Fall 2013 edition. Course book provided along with the course. Course Description This course introduces programming in C++ and

More information

C++_ MARKS 40 MIN

C++_ MARKS 40 MIN C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014 Abstract Classes and Methods

More information

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED - Polymorphism - Virtual Functions - Abstract Classes - Virtual

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP OOP Object oriented programming Polymorphism Encapsulation Inheritance OOP Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes

More information

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

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017 OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OPERATOR OVERLOADING KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Dynamic Memory Management

More information

C++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator

C++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator C++ Addendum: Inheritance of Special Member Functions Constructors Destructor Construction and Destruction Order Assignment Operator What s s Not Inherited? The following methods are not inherited: Constructors

More information

Babaria Institute of Technology Computer Science and Engineering Department Practical List of Object Oriented Programming with C

Babaria Institute of Technology Computer Science and Engineering Department Practical List of Object Oriented Programming with C Practical -1 Babaria Institute of Technology LEARN CONCEPTS OF OOP 1. Explain Object Oriented Paradigm with figure. 2. Explain basic Concepts of OOP with example a. Class b. Object c. Data Encapsulation

More information

Exception Handling in C++

Exception Handling in C++ Exception Handling in C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by

More information

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std; - 147 - Advanced Concepts: 21. Exceptions Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers.

More information

05-01 Discussion Notes

05-01 Discussion Notes 05-01 Discussion Notes PIC 10B Spring 2018 1 Exceptions 1.1 Introduction Exceptions are used to signify that a function is being used incorrectly. Once an exception is thrown, it is up to the programmer

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

CSCI 102 Fall 2010 Exam #1

CSCI 102 Fall 2010 Exam #1 Name: USC Username: CSCI 102 Fall 2010 Exam #1 Problems Problem #1 (14 points) Problem #2 (15 points) Problem #3 (20 points) Problem #4 (16 points) Problem #5 (35 points) Total (100 points) Problem 1 Short

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck C++ Crash Kurs Polymorphism Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ Polymorphism Major abstractions of C++ Data abstraction

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING Unit I : OVERVIEW PART A (2 Marks) 1. Give some characteristics of procedure-oriented

More information

Chapter 6 Introduction to Defining Classes

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

More information

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1 Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function

More information

CSC 330 Object-Oriented Programming. Exception Handling CSC 330

CSC 330 Object-Oriented Programming. Exception Handling CSC 330 Object-Oriented Programming Exception Handling 1 C++ Exception Handling Topics Exception Handling C++ Exception Handling Basics Throwing and Catching Exceptions Constructors, Destructors and Exceptions

More information

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 19 November 7, 2018 CPSC 427, Lecture 19, November 7, 2018 1/18 Exceptions Thowing an Exception Catching an Exception CPSC 427, Lecture

More information

CS105 C++ Lecture 7. More on Classes, Inheritance

CS105 C++ Lecture 7. More on Classes, Inheritance CS105 C++ Lecture 7 More on Classes, Inheritance " Operator Overloading Global vs Member Functions Difference: member functions already have this as an argument implicitly, global has to take another parameter.

More information

PIC10B/1 Winter 2014 Exam I Study Guide

PIC10B/1 Winter 2014 Exam I Study Guide PIC10B/1 Winter 2014 Exam I Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-8 inclusive) 2. Examples/Homework 3. Textbook The midterm will test 1. Your ability to read a program and understand

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

Suppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }

Suppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; } Multiple choice questions, 2 point each: 1. What output is produced by the following program? #include int f (int a, int &b) a = b + 1; b = 2 * b; return a + b; int main( ) int x=1, y=2, z=3;

More information

CS304 Object Oriented Programming

CS304 Object Oriented Programming 1 CS304 Object Oriented Programming 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes?

More information

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 Print Your Name: Page 1 of 8 Signature: Aludra Loginname: CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 (10:00am - 11:12am, Wednesday, October 5) Instructor: Bill Cheng Problems Problem #1 (24

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

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

C++ (classes) Hwansoo Han

C++ (classes) Hwansoo Han C++ (classes) Hwansoo Han Inheritance Relation among classes shape, rectangle, triangle, circle, shape rectangle triangle circle 2 Base Class: shape Members of a class Methods : rotate(), move(), Shape(),

More information

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition? IBS Software Services Technical Interview Questions Q1. What is the difference between declaration and definition? The declaration tells the compiler that at some later point we plan to present the definition

More information

Object Oriented Programming with c++ Question Bank

Object Oriented Programming with c++ Question Bank Object Oriented Programming with c++ Question Bank UNIT-1: Introduction to C++ 1. Describe the following characteristics of OOP. i Encapsulation ii Polymorphism, iii Inheritance 2. Discuss function prototyping,

More information

Java Programming Lecture 7

Java Programming Lecture 7 Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used

More information

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University (12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

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

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information