Object Oriented Programming Lecture 14 Object Oriented Programming
Introduction What is object oriented programming? Example: Abstraction Encapsulation Inheritance Example: Think about an object in real world Mobile
Structure We define struct in previous lecture. You can encapsulate data about an object in a new data type. Example:
Class Classes are an expanded concept of data structures they can contain data members. they can also contain functions as members. Function show behavior of an object.
Example
Example
Public and Private attribute/Function Object can have attribute with private access and public access from outside of view. Think about mobile. What is public? What is private? So we can have several type of access in OOP.
Syntax
Define and usage To define an object from class: Example <class name> <object name>; Example Usage: like structs: . Operator for normal object. -> operator for pointer object.
Initialization and destroy We can define two special function: First: when execute, initialize object. Second: when execute, destroy object. Syntax: Initializer: A function without data type and same name of class. Destroyer: A function without data type, ~same name of class
Example
Example
Input Output in C++ We can use cin and cout for input/output in c++. Syntax: For input: cin>> variable_name; For output Cout<< variable_name;
Overloading Can we define two function with same name? Yes, but parameter must be different.
What is wrong?