tailieunhanh - Lecture Object oriented programming - Lecture no 15

In this chapter we will cover another group of control statements called repetition statements. Repetition statements control a block of code to be executed for a fixed number of times or until a certain condition is met. We will describe Java’s three repetition statements: while, do–while, and for. | CSC241: Object Oriented Programming Lecture No 15 Previous Lecture Function overriding Example program Stack class – stack2 class push() and pop() Distance class – Distsign class getdist() and setdist() Class hierarchy Employee program Employee class Scientist class Manager class Laberor class Today’s Lecture Abstract class Public and private Inheritance Example program Level of inheritance Abstract base class Classes used only for deriving other classes, as employee, are sometimes loosely called abstract classes, meaning that no actual instances (objects) of this class are created public and private Inheritance Class manager : public employee The keyword public specifies that objects of the derived class are able to access public member functions of the base class When this keyword is not used, objects of the derived class cannot access public member functions of the base class Result is that no member of the base class is accessible to objects of the derived class Cont. public . | CSC241: Object Oriented Programming Lecture No 15 Previous Lecture Function overriding Example program Stack class – stack2 class push() and pop() Distance class – Distsign class getdist() and setdist() Class hierarchy Employee program Employee class Scientist class Manager class Laberor class Today’s Lecture Abstract class Public and private Inheritance Example program Level of inheritance Abstract base class Classes used only for deriving other classes, as employee, are sometimes loosely called abstract classes, meaning that no actual instances (objects) of this class are created public and private Inheritance Class manager : public employee The keyword public specifies that objects of the derived class are able to access public member functions of the base class When this keyword is not used, objects of the derived class cannot access public member functions of the base class Result is that no member of the base class is accessible to objects of the derived class Cont. public inheritance represents is a relationship Base class : access specifier Type of inheritance Public inheritance Protected inheritance Private inheritance Public Public in derived class Protected in derived class Private in derived class Protected Protected in derived class Protected in derived class Private in derived class Private Hidden in derived class Hidden in derived class hidden in derived class Access Combinations class A { private: int privdataA; protected: int protdataA; public: int pubdataA; }; int z; B objB; z = ; z = ; z = ; class B : public A { public: void access() { int x; x = privdataA; x = protdataA; x = pubdataA; } }; class C : private A { public: void access() { int y; y = privdataA; y = protdataA; y = pubdataA; } }; z = ; z = ; z = ; Go to program Cont. Derived class Functions can access protected and public member in base class (in case of public, protected and private inheritance) Objects

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.