Suche senden
Hochladen
Java研修 継承
•
0 gefällt mir
•
246 views
S
Shuhei Yamamoto
Folgen
新人へのJava研修を依頼されて作ったもの。 入門書レベルに到達していることが前提。
Weniger lesen
Mehr lesen
Ingenieurwesen
Melden
Teilen
Melden
Teilen
1 von 21
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
早稲田大学授業 - Java Programing上級
早稲田大学授業 - Java Programing上級
Ippei Arita
defjs をひも解く
defjs をひも解く
Masafumi Oyamada
pi-9. スーパークラス, サブクラス, 継承
pi-9. スーパークラス, サブクラス, 継承
kunihikokaneko1
第四回iOSアプリ勉強会
第四回iOSアプリ勉強会
Daisuke Tsukagoshi
pi-13. 今までの総まとめ
pi-13. 今までの総まとめ
kunihikokaneko1
pi-15. カプセル化, MVCモデル, オブジェクトのマッピング
pi-15. カプセル化, MVCモデル, オブジェクトのマッピング
kunihikokaneko1
Xtend の紹介
Xtend の紹介
Oda Shinsuke
Javaセキュアコーディングセミナー東京第1回 講義
Javaセキュアコーディングセミナー東京第1回 講義
JPCERT Coordination Center
Empfohlen
早稲田大学授業 - Java Programing上級
早稲田大学授業 - Java Programing上級
Ippei Arita
defjs をひも解く
defjs をひも解く
Masafumi Oyamada
pi-9. スーパークラス, サブクラス, 継承
pi-9. スーパークラス, サブクラス, 継承
kunihikokaneko1
第四回iOSアプリ勉強会
第四回iOSアプリ勉強会
Daisuke Tsukagoshi
pi-13. 今までの総まとめ
pi-13. 今までの総まとめ
kunihikokaneko1
pi-15. カプセル化, MVCモデル, オブジェクトのマッピング
pi-15. カプセル化, MVCモデル, オブジェクトのマッピング
kunihikokaneko1
Xtend の紹介
Xtend の紹介
Oda Shinsuke
Javaセキュアコーディングセミナー東京第1回 講義
Javaセキュアコーディングセミナー東京第1回 講義
JPCERT Coordination Center
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Weitere ähnliche Inhalte
Empfohlen
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Empfohlen
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Java研修 継承
1.
Java研修 7.継承 山本
2.
1.継承のおさらい
3.
継承のクラス図 Parent field1 field2 methodA methodB Child methodA methodB サブクラス (別名:派生クラス、子クラス、拡張クラス) スーパークラス (別名:基底クラス、親クラス) Parent を継承したものがChild class Child
extends Parent { … }
4.
サブクラスのインスタンス Human #name #strengthLevel +eat +sleep Programmer -javaSkillLevel +writesCode +debugCode クラス(設計図) インスタンス(オブジェクト) kato name strengthLevel javaSkillLevel eat sleep writesCode debugCode サブクラスは、スーパーク ラスのメンバ(フィールド、 メソッド)を引き継ぐ Programmerクラスの katoインスタンスを作成
5.
2.継承の本質
6.
継承の原則 • サブクラスはスーパーク ラスのメンバを引き継ぐ • スーパクラスの方がサブ クラスより抽象度が高い •
子クラス is 親クラス – ○:柴犬 is 犬 – ○:柴犬 is 動物 – ×:犬 is 柴犬 – ×:動物 is 柴犬 動物 人間 プログラマ 犬 柴犬 抽 象 的 具 体 的
7.
包含関係 動物 人間 犬 プログラマ 柴犬 チワワ ラフコリー 柴犬 犬 動物 ○:原則順
×:原則と逆順
8.
継承のメリット • サブクラスはスーパー クラスのメンバを引き継 ぐ • 共通メンバをスーパー クラスにまとめ、サブク ラスは差分コーディン グで済む •
重複コードの排除 動物 名前 体力 人間 犬 食べる 寝る
9.
関連性のない継承はダメ、ゼッタイ! • メンバを利用したいからといって、安易に関連 性のない継承をしてはいけない Human name age eat sleep Dog Human name age eat sleep work Dog もしスーパークラスが 改修されたら… 仕事ができる犬が 誕生してしまう おっ、ちょうどいいメ ンバが揃ったクラス があるじゃ~ん。 継承しよっと! class
Dog extends Human { … }
10.
多重継承はできない仕様 オレたち オレンジ からたち ※ちなみにオレタチは本当にあります。 「オレンジ」と「からたち」を合成して「オレたち」っ ていうキメラ果実をつくったぞ! よし、両方の性質があるから2つ継承しよう! (Javaの仕様上、許されていない)
11.
演習7-1 • 以下の内、正しいコードはどれか。 1. Human
kato1 = new Human(); 2. Human kato2 = new Programmer(); 3. Programmer kato3 = new Human(); 4. Programmer kato4 = new Programmer(); Human Programmer 正しい →コンパイルできる
12.
宿題 • 加藤さん2号はいったい何者なの? – Human
kato2 = new Programmer();
13.
3.引き継ぎをもっと詳しく
14.
引き継がないもの • 原則 – サブクラスはスーパークラスのメンバを引き継ぐ •
例外 – コンストラクタ → 動作がトリッキー
15.
演習7-2 • Run_7_2クラスのmainメソッドを実行せよ。 – Human,
Programmerクラスともに、以下のコンスト ラクタを実装している Human() { System.out.println("Humanクラスのコンストラクタが実行されました。"); } Programmer() { System.out.println("Programmerクラスのコンストラクタが実行されました。"); } Human Programmer
16.
サブクラスをnewしたときに起こること 1. スーパークラスのインスタンス生成 2. サブクラスのインスタンス生成 –
スーパークラスのメンバ引継 3. スーパークラスのコンストラクタ実行 – サブクラスにコンストラクタがあると、最初にスパ ークラスのコンストラクタを呼び出す – サブクラスで明示しない限り、引数なしのコンス トラクタが呼び出される 4. サブクラスのコンストラクタ実行
17.
演習7-3 • Programmerクラスに以下のコンストラクタを 実装せよ。 Human #name: String #strengthLevel:
int Programmer -javaSkillLevel: int 第1引数 String型 → Humanクラスのnameフィールドへ代入 第2引数 int型 → HumanクラスのstrengthLevelフィールドへ代入 第3引数 int型 → ProgrammerクラスのjavaSkillLevelフィールドへ代入 Programmerコンストラクタ //加藤さん4号インスタンス作成 Programmer kato4 = new Programmer("加藤",100, 60); 参考)mainメソッドのインスタンス生成文
18.
オーバーライド • スーパークラスのメソッドを、サ ブクラスで再定義可能 – Programmerクラスでは、Human クラスとは異なるeat,
sleepメソッ ドの実装ができる • オーバーライドの条件 – メソッド名や、引数、戻り値を揃 える必要がある Human #name #strengthLevel +eat +sleep Programmer +eat +sleep
19.
演習7-3 • Run_7_3クラスのmainメソッドを実行 せよ。 • Programmerクラスに以下のメソッドを オーバーライドし、再実行せよ。 –
eatメソッド • プログラマは多忙を極め、食事はコンビ ニ弁当等の栄養に偏りがあるもので済 ませがちであるため、体力の回復量を Humanクラスの半分にせよ。 – sleepメソッド • プログラマは多忙を極め、帰宅が遅く、 睡眠時間が短くなりがちなため、体力の 回復量をHumanクラスの半分にせよ。 Human #name #strengthLevel +eat +sleep Programmer -javaSkillLevel +writesCode +debugCode
20.
4.実装しない継承
21.
抽象クラスと抽象メソッド • 抽象クラス – abstract修飾子がついたクラス –
インスタンスの作成不可 →インスタンス化はサブクラスに委ねる • 抽象メソッド – abstract修飾子がついたメソッド – 実装不可 →実装はサブクラスのオーバーライドに委ねる そしてインタフェースへ…
Jetzt herunterladen