Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
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.
Vorschau wird generiert...
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.
… Tải file gốc để đọc toàn bộ tài liệu.
- 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
- Giang Le
Häufig gestellte Fragen
Tài liệu này có miễn phí không?
Có. “Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou” miễn phí — bạn chỉ cần đăng nhập rồi bấm Tải xuống để lấy file gốc.
Tài liệu dài bao nhiêu trang?
Tài liệu gồm 1 trang, thuộc môn Lập trình Java. Bạn có thể xem trước online trước khi tải.
Tôi có thể xem trước trước khi tải không?
Có. Bạn xem trước tài liệu ngay trên trang này bằng trình đọc online, rồi quyết định tải về.

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