Classes and Inheritance

Slides:



Advertisements
Similar presentations
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Advertisements

Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
ITF11006.NET Inheritance. Classes and Inheritance Constructors and Inheritance Modifiers Interfaces Operators.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
Advanced Object-Oriented Programming Features
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
 Simple payroll application that polymorphically calculates the weekly pay of several different types of employees using each employee’s Earnings method.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Object Oriented Concepts
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
Inheritance in the Java programming language J. W. Rider.
CIS 3301 C# Lesson 7 Introduction to Classes. CIS 3302 Objectives Implement Constructors. Know the difference between instance and static members. Understand.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Module 10: Inheritance in C#. Overview Deriving Classes Implementing Methods Using Sealed Classes Using Interfaces Using Abstract Classes.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
1. 2  Classes are not just containers for methods ◦ Virtually all are classes ◦ Blueprint/Cookie Cutter/Recipe ◦ Objects – instance of the class (new)
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Class Relationships And Reuse Interlude 4 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
ISBN Object-Oriented Programming Chapter Chapter
Introduction to Object-Oriented Programming Lesson 2.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
C#.Net Software Development Version 1.0. Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Introduction to Object-oriented Programming
OOP: Encapsulation &Abstraction
Object-Oriented Programming Concepts
Chapter 12 OOP: Polymorphism, Interfaces and Operator Overloading
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
Object-Oriented Programming: Inheritance
2.7 Inheritance Types of inheritance
Inheritance and Polymorphism
Java Primer 1: Types, Classes and Operators
Inheritance AKEEL AHMED.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
C++ Classes C++ Interlude 1.
Module 4: Implementing Object-Oriented Programming Techniques in C#
Can perform actions and provide communication
Figure 8.1 Inheritance: Relationships among timepieces.
Can perform actions and provide communication
Lecture 22 Inheritance Richard Gesick.
Abstract Classes AKEEL AHMED.
Advanced Java Topics Chapter 9
Classes & Objects: Examples
METHOD OVERRIDING in JAVA
Can perform actions and provide communication
Java Programming, Second Edition
Object-Oriented Programming
Fundaments of Game Design
CIS 199 Final Review.
Chapter 11 Class Inheritance
Chapter 11 Inheritance and Encapsulation and Polymorphism
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Figure 8.1 Inheritance: Relationships among timepieces.
Presentation transcript:

Classes and Inheritance 靜宜大學資工系 蔡奇偉副教授 ©2011

大綱

Class Inheritance Base Class Derived Class

Accessing the Inherited Members

All Classes Are Derived from Class object

Hiding Members of a Base Class

Base Access keyword base

Using References to a Base Class An instance of a derived class consists of an instance of the base class, plus the additional members of the derived class. A reference to the derived class points to the whole class object, including the base class part. If you have a reference to a derived class object, you can get a reference to just the base class part of the object by casting the reference to the type of the base class by using the cast operator. The cast operator is placed in front of the object reference and consists of a set of parentheses containing the name of the class being cast to.

Virtual and Override Methods

Constructor Execution

Constructor Initializers

use a different constructor from the same class

Class Access Modifiers

Inheritance Between Assemblies

Member Access Modifiers

Regions Accessing a Member

Public Member Accessibility

Private Member Accessibility

Protected Member Accessibility

Internal Member Accessibility

Protected Internal Member Accessibility

Summary of Member Access Modifiers

Abstract Members An abstract member is a function member that is designed to be overridden.

Comparing Virtual and Abstract Members

Abstract Classes

Sealed Classes

Static Classes A static class is a class where all the members are static. Static classes are used to group data and functions that are not affected by instance data. A common use of a static class might be to create a math library containing sets of mathematical methods and values.

Extension Methods