SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Inheritance in Object-Oriented Programming: Concepts and Examples

sirvat avatar
9 diapositives · 236 Views · Jul 27, 2014

This tutorial covers key concepts of inheritance in object-oriented programming, focusing on the relationship between superclasses and subclasses. It illustrates how subclasses inherit attributes and methods from their superclasses, explains the significance of non-private attributes, method overriding, and polymorphism. The tutorial also distinguishes between method overriding and overloading, and highlights important keywords such as 'this' and 'super' in context. Examples demonstrate type casting within a class hierarchy and provide insights into best practices and potential pitfalls.

Understanding Inheritance in Object-Oriented Programming: Concepts and Examples - slide 1
01 / 9Understanding Inheritance in Object-Oriented Programming: Concepts and Examples
1 / 17

Télécharger la présentation

Understanding Inheritance in Object-Oriented Programming: Concepts and Examples
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CPSC 233 Tutorial Xin Mar 14, 2011

  2. Inheritance • super class – sub class • generic – specific • sub class inherits • non-private attributes • non-private methods • sub class defines new attributes & methods

  3. UML representation • Hollow triangle

  4. Gramma public class superClass { // … } public classsubClassextendssuperClass { // Definition of subclass – only what is unique to subclass }

  5. Method overriding/polymorphism • Redefine a method with the same signature (name, parameters, and returned value) • As opposed to overloading, which defines methods with different signatures • this: pointing to the current object • super: pointing to the super class • super.method ( ) • super.attribute (shadowing, not good)

  6. Example 1

  7. Example -> use of super

  8. Reference Casting • public class SuperClass {} • public class SubClass extend SuperClass{} • SuperClass sup = new SubClass(); // ✔ no casting needed • SubClass sub = (SubClass) sup; // ✔ casting needed; sup must be an object of SubClass • SubClass sub2 = (SubClass) new SuperClass () // ✗ • Casting between different classes not in a hierarchy is not allowed

  9. Example 3 type casting