Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University

Similar presentations


Presentation on theme: "Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University"— Presentation transcript:

1 Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University http://softuni.bg

2 2 1.Fundamental Principles of OOP 2.Inheritance ▪ Class Hierarchies ▪ Inheritance and Access Levels Table of Contents

3 3 sli.do #3666 Questions

4 Fundamental Principles of OOP

5 ▪Encapsulation ▪Inheritance ▪ Inherit members from parent class ▪ Inherit constructors from parent class ▪ Polymorphism ▪ Abstraction Fundamental Principles of OOP 5

6 Inheritance

7 Types of Inheritance derived class base class / parent class inherits 7

8 Types of Inheritance (2) interface class implements 8

9 Types of Inheritance (3) derived interface base interface extends 9

10 1. Extensibility 2. Reusability 3. Provides abstraction Inheritance – Benefits 10

11 Don't use it to build has-a relationship E.g. dog has-a name (dog is not a name) Examples - Incorrect 11

12 Use inheritance for building is-a relationship E.g. dog is-a animal (dog is an animal) Examples - Correct 12

13 13 How to Define Inheritance? class DerivedClass extends BaseClass

14 14 Use super to invoke the parent constructor How to Define Inheritance? (2) public Circle(int x, int y) { super(x, y); }

15 Exercises in Class

16 16 Private members are hidden Inaccessible Members

17 17 Inheritance – Example Person +Name: string +Address: string Employee +Company: string +Salary: decimal Student +School: string Base class Derived class

18 Class Hierarchies Game MultiplePlayersGame BoardGame Chess Backgammon SinglePlayerGame Minesweeper Solitaire 18

19 Simple Inheritance Live Demo

20 20 ▪ public ▪ private ▪ protected ▪no modifier Access Modifiers in Java

21 21 There is no multiple inheritance Inheritance: Important Aspects

22 22 Constructors are not inherited Inheritance: Important Aspects (2)

23 23 Extended class could add new members, but couldn’t remove derived members Inheritance: Features

24 24 New members with the same name or signature hide the inherited ones Inheritance: Features (2)

25 Exercises in Class

26 26 UML class diagrams Inheritance Hierarchies

27 27 UML Class Diagram – Example

28 Class Diagrams in IntelliJ Idea Live Demo

29 29 ▪Inheritance allows extending the behavior of the classes ▪ Inheriting Fields ▪ Inheriting Methods ▪ Reusing the existing code Summary

30 ? ? ? ? ? ? ? ? ? OOP – Encapsulation https://softuni.bg/java-basics-oop

31 License ▪ This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 31 ▪ Attribution: this work may contain portions from ▪ "Fundamentals of Computer Programming with Java" book by Svetlin Nakov & Co. under CC-BY-SA licenseFundamentals of Computer Programming with JavaCC-BY-SA ▪ "OOP" course by Telerik Academy under CC-BY-NC-SA licenseOOPCC-BY-NC-SA

32 Free Trainings @ Software University ▪ Software University Foundation – softuni.orgsoftuni.org ▪ Software University – High-Quality Education, Profession and Job for Software Developers ▪ softuni.bg softuni.bg ▪ Software University @ Facebook ▪ facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity ▪ Software University @ YouTube ▪ youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity ▪ Software University Forums – forum.softuni.bgforum.softuni.bg


Download ppt "Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University"

Similar presentations


Ads by Google