Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- Seiten
- 1
- Định dạng
- DOCX
- Dung lượng
- 6.8 KB
- Trường
- University of California, Berkeley
- Aufrufe
- 0
- Kommentare
- 0
- Lượt tải
- 0
Vorschau wird generiert...
Tài liệu ghi chú về kế thừa trong Java, giải thích về ghi đè (overriding) và nạp chồng (overloading) phương thức, quy tắc chữ ký, kiểu trả về và phạm vi truy cập.
- Dokumentenname
- Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- Schule / Kurs
- University of California, Berkeley · Lập trình Java
- Inhalt
- Tài liệu giải thích sự khác biệt giữa ghi đè và nạp chồng phương thức trong Java. Ghi đè yêu cầu chữ ký phương thức giống hệt, trong khi nạp chồng cho phép cùng tên nhưng khác tham số. Các vấn đề về kiểu trả về và bộ truy cập cũng được đề cập.
- Inhaltsverzeichnis
- Dieses Dokument hat kein eindeutiges Inhaltsverzeichnis.
- Seiten
- 1 Seiten
- Hochgeladen von
- Uni24h
Beschreibung
Trích nội dung tài liệu
Overriding and overloading Method overriding only occurs if the method signature is exactly the same. Let's take a look at the following classes: public class Bird { public void gulgate(Bird b) { ... } } public class Falcon { public void gulgate(Bird b) { ... } public void gulgate(Falcon f) { ... } } Here, Falcon::gulgate(Bird) overrides Bird::gulgate(Bird) since the method signatures are exactly the same. Falcon::gulgate(Falcon) is an example of method overloading, where the name of the function is the same but the argument that it takes in. Different return types If we had a method in Bird with the signature "public int gulgate(Falcon f)" (same signature as Falcon::gulgate(Falcon) but with a different return type), Java wouldn't allow this and would complain during compilation that the return types are not compatible (void from Falcon::gulgate(Falcon) and int from Bird::gulgate(Falcon)). Different access modifiers When the access modifiers are different, something slightly different will happen (I think this link describes it pretty well! Ctrl-F for "Overriding and Access-Modifiers") but don't worry about this too much since we haven't covered access modifiers in depth during lecture yet.
Häufig gestellte Fragen
Ist dieses Dokument kostenlos?
Ja. „Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou“ ist kostenlos — melden Sie sich einfach an und klicken Sie auf Herunterladen, um die Originaldatei zu erhalten.
Wie viele Seiten hat dieses Dokument?
Das Dokument hat 1 Seiten, für den Kurs Lập trình Java. Sie können es vor dem Herunterladen online in der Vorschau ansehen.
Kann ich vor dem Herunterladen eine Vorschau ansehen?
Ja. Sie können sich dieses Dokument direkt auf dieser Seite im Online-Reader ansehen und dann entscheiden, ob Sie es herunterladen möchten.
Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Vorschau wird generiert...
Trích nội dung tài liệu
Overriding and overloading Method overriding only occurs if the method signature is exactly the same. Let's take a look at the following classes: public class Bird { public void gulgate(Bird b) { ... } } public class Falcon { public void gulgate(Bird b) { ... } public void gulgate(Falcon f) { ... } } Here, Falcon::gulgate(Bird) overrides Bird::gulgate(Bird) since the method signatures are exactly the same. Falcon::gulgate(Falcon) is an example of method overloading, where the name of the function is the same but the argument that it takes in. Different return types If we had a method in Bird with the signature "public int gulgate(Falcon f)" (same signature as Falcon::gulgate(Falcon) but with a different return type), Java wouldn't allow this and would complain during compilation that the return types are not compatible (void from Falcon::gulgate(Falcon) and int from Bird::gulgate(Falcon)). Different access modifiers When the access modifiers are different, something slightly different will happen (I think this link describes it pretty well! Ctrl-F for "Overriding and Access-Modifiers") but don't worry about this too much since we haven't covered access modifiers in depth during lecture yet.
- Dokumentenname
- Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- Schule / Kurs
- University of California, Berkeley · Lập trình Java
- Inhalt
- Tài liệu giải thích sự khác biệt giữa ghi đè và nạp chồng phương thức trong Java. Ghi đè yêu cầu chữ ký phương thức giống hệt, trong khi nạp chồng cho phép cùng tên nhưng khác tham số. Các vấn đề về kiểu trả về và bộ truy cập cũng được đề cập.
- Inhaltsverzeichnis
- Dieses Dokument hat kein eindeutiges Inhaltsverzeichnis.
- Seiten
- 1 Seiten
- Hochgeladen von
- Uni24h
Kommentare (0)
Noch keine Kommentare. Seien Sie der Erste!
Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines
Asymptotics II, Search Trees (Discussion 7) (Kỹ thuật phân tích thời gian chạy, cây tìm kiếm nhị phân) - Christine Zhou
Introduction to Java (Discussion 1) (Giới thiệu về Java) - Christine Zhou
More Sorting (Discussion 13) (Thuật toán sắp xếp nâng cao) - Christine Zhou
Giáo trình Lập trình Java
Tổng hợp Đề Toán 5 - Luyện thi vào Lớp 6 - CLB EMath
Bài giảng vật lý đại cương (Chương 3) - Đỗ Ngọc Uấn
Chương 8.Nguyên tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 7.Cơ học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 6.Quang học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang

Kommentare (0)
Noch keine Kommentare. Seien Sie der Erste!