Object-Oriented Programming. Lecture 2 Dr Piotr Cybula

Similar documents
Object-Oriented Programming. Lecture 4 Dr Piotr Cybula

G52CPP C++ Programming Lecture 13

G52CPP C++ Programming Lecture 9

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

And Even More and More C++ Fundamentals of Computer Science

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

C++ Inheritance and Encapsulation

CS304 Object Oriented Programming Final Term

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

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

Object-Oriented Programming

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli


Classes - 2. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Inheritance and Encapsulation


LECTURE 03 LINKED LIST

Object Oriented Design

Class 15. Object-Oriented Development from Structs to Classes. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Abstraction in Software Development

C++ (Non for C Programmer) (BT307) 40 Hours

CPSC 427a: Object-Oriented Programming

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Encapsulation in C++

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

Object oriented programming with C++

CS1004: Intro to CS in Java, Spring 2005

CS24 Week 4 Lecture 1

Principles of Object Oriented Programming. Lecture 4

CS 162, Lecture 25: Exam II Review. 30 May 2018

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

Object Oriented Programming. Solved MCQs - Part 2

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

OBJECT ORIENTED PROGRAMMING USING C++

Linked List using a Sentinel

(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University

Object-Oriented Programming, Iouliia Skliarova

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

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

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

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

Object Oriented Software Design II

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm

Chapter 5 Object-Oriented Programming

Constants, References

6.096 Introduction to C++ January (IAP) 2009

Intro. Classes Beginning Objected Oriented Programming. CIS 15 : Spring 2007

CS304 Object Oriented Programming

EL2310 Scientific Programming

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

What does it mean by information hiding? What are the advantages of it? {5 Marks}

UEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class

C++ Important Questions with Answers

Introduction Of Classes ( OOPS )

lecture09: Linked Lists

6.096 Introduction to C++

Chapter 11. Abstract Data Types and Encapsulation Concepts

Classes. Christian Schumacher, Info1 D-MAVT 2013

Outline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor

Object-Oriented Principles and Practice / C++

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Introduction to Programming Using Java (98-388)

C++ : Object Oriented Features. What makes C++ Object Oriented

Intermediate Programming, Spring 2017*

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

Abstract Data Types and Encapsulation Concepts

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

Friendship in Service of Testing

CS427 Inheritance and Virtual Functions. Linked lists. 2/27. 01Replacement.cpp link! i n t GetY ( void ) { return ( y ) ; } ;

Lecture 8: Object-Oriented Programming (OOP) EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

Short Notes of CS201

Programming 2. Object Oriented Programming. Daniel POP

Chapter 15: Object Oriented Programming

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

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

Starting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,

Implementing Subprograms

CS201 - Introduction to Programming Glossary By

An Introduction to C++

EL2310 Scientific Programming

Programming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor

G52CPP C++ Programming Lecture 12

EECE.3220: Data Structures Spring 2017

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES III

CISC 2200 Data Structure Fall, C++ Review:3/3. 1 From last lecture:

Friends and Overloaded Operators

What is an algorithm?

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

COMP6771 Advanced C++ Programming

CPSC 427a: Object-Oriented Programming

Friends and Overloaded Operators

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

What is an algorithm?

Do not write in this area TOTAL. Maximum possible points: 75

Question 1 Consider the following structure used to keep employee records:

Transcription:

Object-Oriented Programming Lecture 2 Dr Piotr Cybula <cybula@math.uni.lodz.pl>

Encapsulation : data protection code safety and independence better team support with the code separation without «giving a monkey a razor» (black-box solution) different levels of data access in a class (through access specifiers): public available for everyone private available only for the member functions of that class (methods) protected like private, but additionally available for the inherited classes friend available for implicitly pointed non-member functions or other classes constant methods guaranteeing no changes of an object they are called for 2/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz

Data protection : struct Within the struct statement all members are public by default: struct List private: //hidden members int value; List *next; void printlist(); //internal method public: //public interface List(int _value = 0); List(const List &node); ~List(); int getvalue() const return value; } //getter method void setvalue(int _value) value = _value; } //setter method //other methods }; List x(1); x.setvalue(2); //public method call x.printlist(); //compile-time error 3/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz

Data protection : class Within the class statement all members are private by default: class List //hidden members, private keyword optional int value; List *next; void printlist(); //internal method public: //public interface List(int _value = 0); List(const List &node); ~List(); int getvalue() const return value; } //getter method void setvalue(int _value) value = _value; } //setter method //other methods }; List x(1); x.setvalue(2); //public method call x.printlist(); //compile-time error 4/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz

Static members Static fields: common memory variables shared by all objects of a class available for all methods of a class declared inside a class, but initialised outside with scope operator (::) regardless of the access specifier used Static methods: working for the class, not for a particular object called by the class with scope operator or by its objects with dot operator cannot access the ordinary object members (only static) 5/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz

Static members class List int value; List *next; static List *head; //static field, one for the whole class void printlist(); //internal method public: List(int _value = 0); List(const List &node); ~List(); static void print() //static method head->printlist(); //ok, head is the static field next->printlist(); //compile-time error, next is non-static } }; List *List::head = NULL; //initialisation of the static field List::print(); //static method call List::head = new List; //compile-time error, private field 6/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz

this the pointer to the object which a method is called for passed to each method as the first implicit parameter List::List(int _value = 0) this->value = _value; this->next = head; head = this; cout << "Constructor: "; this->printlist(); } List::List(int _value = 0) value = _value; next = head; head = this; cout << "Constructor: "; printlist(); } 7/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz

Friend functions external functions declared by a class as friends full or read-only access to the private members of the class objects given as parameters or created locally class List int value; List *next; static List *head; void printlist(); public: //methods friend int look(const List &node); //friendship declaration }; int look(const List &node) //friend function definition node.next = NULL; //compile-time error, read-only access return node.value; //access to the private member of object } 8/8 Object-Oriented Programming, Lecture 2, dr Piotr Cybula, University of Lodz