OOP Questions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Levels of Encapsulation

1. Public 2. Protected 3. Private 4. Internal 5. Protected Internal

Abstract class

Class that cannot be instantiated

Rules for Constructors

Constructor Name should be the same as class name Constructor must have no return type

Operator overloading

Function where different operators are applied

Manipulator

Functions that can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. - e.g. endl and setw

Virtual function

Member function of class and its functionality can be overridden in its derived class.

Inline function

Technique used by compilers and instructs to insert complete body of the function wherever that function is used in the program source code.

Function overloading

Normal function with ability to perform different tasks. Allows creation of several methods with the same name which differ from each other by type of input and output of the function e.g. void add(int& a, int& b); void add(double& a, double& b); void add(struct bob& a, struct bob& b);

OOPS

Object Oriented Programming System - Programs are considered as a collection of objects - Each object is nothing but an instance of a class.

Constructor

Method used to initialize the state of an object Gets invoked at the time of object creation

Basic Concepts of OOPS

- Abstraction - Encapsulation - Inheritance - Polymorphism

Polymorphism

- Assigning behavior or value in a subclass to something already defined in the main class. - Takes more than one form - The provision of a single interface to entities of different types. The ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers to many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism.

Encapsulation

- Bundling of data with the methods that operate on that data - Used to hide the values or state of a structured data object inside a class Encapsulation is placing the data and the functions that work on that data in the same place. While working with procedural languages, it is not always clear which functions work on which variables but object-oriented programming provides you framework to place the data and the relevant functions together in the same object.

Big O Notation

- Description of the performance/complexity of an algorithm - Specifically worst-case scenario - Can be used to describe runtime or space used

Linked lists

- Dynamic size - Ease of insertion/deletion - Random access is not allowed. We have to access elements sequentially starting from the first node. - Cannot do binary search - Extra memory space for a pointer is required with each element of the list. - Arrays have better cache locality that can make a pretty big difference in performance.

Object

- Instance of a class - Has its own state, behavior, and identity - This is the basic unit of object oriented programming. - Unit that bundles both data and function that operate on data

Inheritance

- One class shares the structure and behavior defined in another class. - Single Inheritance if applied on one class. - Multi Inheritance if applied on multiple classes. One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class. This is a very important concept of object-oriented programming since this feature helps to reduce the code size.

Abstraction

- Providing only essential information to the outside world and hiding their background details, - To represent the needed information in program without presenting the details. For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides different methods to the outside world without giving internal detail about those methods and data.

Class

- Representation of a type of object - Blueprint/Template that describes the details of an object. - This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.

Array

- Size is fixed, so must know upper limits of array in advance - Inserting/Deleting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.

Overloading

- branch of polymorphism. - When the exiting operator or function is made to operate on new data type

Friend function

Friend of a class that is allowed access to public, private, or protected data in that same class. Cannot access information if function is defined outside the class. Can be declared anywhere in the class declaration Cannot be affected by access control keywords like private, public, or protected

Destructor

Method automatically called when the object is created or destroyed Name is same as class name with ~ beforehand


Ensembles d'études connexes

Biology Plant cells, Animal cells, and osmosis

View Set

Ch 12 Compensating the Flexible Workforce

View Set