1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Object oriented programming - Lecture No 14

15 24 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 15
Dung lượng 83,19 KB

Nội dung

After you have read and studied this chapter, you should be able to: Define a class with multiple methods and data members, differentiate the local and instance variables, define and use value-returning methods, distinguish private and public methods, distinguish private and public data members, pass both primitive data and objects to a method.

CSC241: Object Oriented Programming Lecture No 14 Previous Lecture • Protected members • Generalization in UML representation • • • Example program – Counter – CountDn A a1; C *c1 = new Derived class C; B b1; – Constructor … – Destructor delete c1; C c1; Function overriding class class A A ~A() { A() { } } class class B B ~B() { B() { } } class class C C ~C() { C() { } } A() ~A() { } { } ~B( B() ) { } { } ~C( C() ) { } { } Today’s Lecture • Function overriding – • Example program – Distance class Class hierarchy – Employee program • Public and private Inheritance • Level of inheritance Overriding Member Functions • • Member functions in a derived class can be override, i.e have the same name as those in the base class Stack, a simple data storage medium It allowed you to push integers onto the stack and pop them off class A abc(int x) { } class B abc(int x) { } class Stack { protected: int st[3]; int top; public: Stack() { top = -1; } void push(int var) { st[++top] = var; } int pop() { return st[top ]; } }; Stack2 s1; s1.push(11); s1.push(22); s1.push(33); cout

Ngày đăng: 20/09/2020, 13:26

TỪ KHÓA LIÊN QUAN

w