Class Inheritance SWE 344 Internet Protocols & Client Server Programming.

Slides:



Advertisements
Similar presentations
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Advertisements

INHERITANCE BASICS Reusability is achieved by INHERITANCE
IEG 3080 Tutorial 2 Jack Chan. Prepared by Jack Chan, Spring 2007 Outline.Net Platform Object Oriented Concepts Encapsulation Inheritance Polymorphism.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
Section 5 – Classes. Object-Oriented Language Features Abstraction –Abstract or identify the objects involved in the problem Encapsulation –Packaging.
IEG3080 Tutorial 3 Prepared by Ryan. Outline Object Oriented Programming Concepts Encapsulation Inheritance Polymorphism Delegation Course Project.
CSCI 143 OOP – Inheritance 1. What is Inheritance? A form of software reuse Create a new class from an existing class – Absorb existing class data and.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Advanced Object-Oriented Programming Features
CS221 - Computer Science II Polymorphism 1 Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is.
LECTURE 07 Programming using C# Inheritance
Inheritance and Polymorphism 7. Building Applications Using C# / Session 7 © Aptech Ltd. Objectives  Define and describe inheritance  Explain method.
Inheritance Chapter 14. What is inheritance?  The ability to create a class from another class, the “parent” class, extending the functionality and state.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
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.
CS305j Introduction to Computing Inheritance and Polymorphism 1 Topic 26 Introduction to Inheritance and Polymorphism "One purpose of CRC cards [a design.
Encapsulation, Inheritance & Polymorphism. OOP Properties Encapsulation ­The process of creating programs so that information within a class is not accessible.
Polymorphic support in C# Let us now examine third pillar of OOP i.e. Polymorphism.. Recall that the Employee base class defined a method named GiveBonus(),
ILM Proprietary and Confidential -
CIS 3301 C# Lesson 7 Introduction to Classes. CIS 3302 Objectives Implement Constructors. Know the difference between instance and static members. Understand.
Programming using C# for Teachers Introduction to Objects Reference Types Functions of Classes Attributes and Types to a class LECTURE 2.
Chapter 10 Inheritance and Polymorphism
Peyman Dodangeh Sharif University of Technology Fall 2014.
Inheritance  Inheritance is a fundamental object-oriented technique  it enhances software design and promotes reuse  We will focus on:  deriving new.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Inheritance  Virtual Function.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
CMSC 202 Polymorphism. 10/20102 Topics Binding (early and late) Upcasting and downcasting Extensibility The final modifier with  methods  classes.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
Inheritance ndex.html ndex.htmland “Java.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
Section 3: Component/Object Oriented Programming, Events, and Delegates in.NET Jim Fiddelke, Greenbrier & Russel.
BY:- TOPS Technologies
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
Today’s Objectives 5-Jul-2006 Announcements
Ch 10- Advanced Object-Oriented Programming Features
Final and Abstract Classes
C# - Inheritance and Polymorphism
Presented By: Nazia Hossain Lecturer, Stamford University
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
OOP’S Concepts in C#.Net
The University of Texas Rio Grande Valley
Interface.
Inherited Classes in Java
Advanced Programming Behnam Hatami Fall 2017.
Inheritance Inheritance is a fundamental Object Oriented concept
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look UTPA – Fall 2012 This set of slides is revised from lecture.
CIS 199 Final Review.
C++ Programming CLASS This pointer Static Class Friend Class
Key Concepts from 1301: What you should already know
Chapter 11 Inheritance and Encapsulation and Polymorphism
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Computer Science II for Majors
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Class Inheritance SWE 344 Internet Protocols & Client Server Programming

 Inheritance is one of the primary concepts of object-oriented programming.  It allows one class to pass on properties and methods to child classes  It allows us to reuse existing code.  Through effective employment of reuse, we can save time in our programming.  C# supports single class inheritance only. Therefore, we can specify only one base class to inherit from.  However, it does allow multiple interface inheritance Class Inheritance 2

Inheritance, together with encapsulation and polymorphism, is one of the three primary characteristics (or pillars) of object-oriented programming. Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. A derived class can have only one direct base class. However, inheritance is transitive. If Class C is derived from Class B, and Class B is derived from Class A, Class C inherits the members declared in Class B and Class A. Class Inheritance 3

A derived class is a specialization of the base class. For example, if you have a base class Animal, you might have one derived class that is named DOG and another derived class that is named CAT. A DOG is an Animal, and a CAT is an Animal, but each derived class represents different specializations of the base class. When you define a class to derive from another class, the derived class implicitly gains all the members of the base class, except for its constructors and destructors. The derived class can thereby reuse the code in the base class without having to re-implement it. In the derived class, you can add more members. In this manner, the derived class extends the functionality of the base class. Class Inheritance 4

class Animal { public Animal() { Console.WriteLine("Animal constructor"); } public void Greet() { Console.WriteLine("Animal says Hello"); } public void Talk() { Console.WriteLine("Animal talk"); } public virtual void Sing() { Console.WriteLine("Animal song"); } }; class Dog : Animal { public Dog() { Console.WriteLine("Dog constructor"); } public new void Talk() { Console.WriteLine("Dog talk"); } public override void Sing() { Console.WriteLine("Dog song"); } }; Class Inheritance 5

Animal a1 = new Animal(); a1.Talk(); a1.Sing(); a1.Greet(); Output Animal constructor Animal talk Animal song Animal says Hello Dog a2 = new Dog(); a2.Talk(); a2.Sing(); a2.Greet(); Output Animal constructor Dog constructor Animal talk Dog song Animal says Hello Class Inheritance 6

using System; public class ParentClass { public ParentClass() { Console.WriteLine("Parent Constructor."); } public void print() { Console.WriteLine("I'm a Parent Class."); } public class ChildClass : ParentClass { public ChildClass() { Console.WriteLine("Child Constructor."); } public static void Main() { ChildClass child = new ChildClass(); child.print(); Console.ReadLine(); } Class Inheritance Parent Constructor. Child Constructor. I'm a Parent Class. 7

8 using System; namespace InheritanceApplication { class Shape { protected int width; protected int height; public void setWidth(int w) { width = w; } public void setHeight(int h) { height = h; } Example of Inheritance

9 // Derived class class Rectangle: Shape { public int getArea() { return (width * height); } class RectangleTester { static void Main(string[] args) {

10 Rectangle Rect = new Rectangle(); Rect.setWidth(5); Rect.setHeight(7); // Print the area of the object. Console.WriteLine("Total area: {0}",Rect.getArea()); Console.ReadKey(); }

END 11