CSE459_CSharp_03_Inheritance

CSE459_CSharp_03_Inheritance - Programming in C#...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Programming in C# Inheritance and Polymorphism CSE 459.24 Prof. Roger Crawfis C# Classes l Classes are used to accomplish: l Modularity: Scope for global (static) methods l Blueprints for generating objects or instances: l Per instance data and method signatures l Classes support l Data encapsulation - private data and implementation. l Inheritance - code reuse Inheritance l Inheritance allows a software developer to derive a new class from an existing one. l The existing class is called the parent, super, or base class. l The derived class is called a child or subclass. l The child inherits characteristics of the parent. l Methods and data defined for the parent class. l The child has special rights to the parents methods and data. l Public access like any one else l Protected access available only to child classes (and their descendants). l The child has its own unique behaviors and data. Inheritance l Inheritance relationships are often shown graphically in a class diagram , with the arrow pointing to the parent class. l Inheritance should create an is-a Animal Bird Examples: Base Classes and Derived Classes Base class Derived classes Student GraduateStudent UndergraduateStudent Shape Circle Triangle Rectangle Loan CarLoan HomeImprovementLoan MortgageLoan Employee FacultyMember StaffMember Account CheckingAccount SavingsAccount Declaring a Derived Class l Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class contents } Controlling Inheritance l A child class inherits the methods and data defined for the parent class; however, whether a data or method member of a parent class is accessible in the child class depends on the visibility modifier of a member....
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 25

CSE459_CSharp_03_Inheritance - Programming in C#...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online