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.
描述
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.
AI 摘要
- 文档名称
- Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- 学校 / 课程
- University of California, Berkeley · Lập trình Java
- 内容
- 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.
- 目录
- 此文档没有清晰的目录。
- 页数
- 1 页
- 上传者
- Uni24h
常见问题
此文档免费吗?
是的。“Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou”是免费的 — 只需登录并点击“下载”即可获取原始文件。
这份文档有多少页?
该文档共有 1 页,适用于课程 Lập trình Java。您可以在下载前进行在线预览。
我可以在下载前预览吗?
是的。您可以通过在线阅读器直接在本页面预览此文档,然后再决定是否下载。
Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
正在生成预览...
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.
阅读全文
- 文档名称
- Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- 学校 / 课程
- University of California, Berkeley · Lập trình Java
- 内容
- 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.
- 目录
- 此文档没有清晰的目录。
- 页数
- 1 页
- 上传者
- Uni24h
评论 (0)
暂无评论。快来抢沙发吧!
Misc.onclusion (Discussion 14-END) (Ôn tập cấu trúc dữ liệu) - Christine Zhou
Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
Giáo trình Lập trình Java
Inheritance (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Asymptotic Analysis (Discussion 7) (Phân tích tiệm cận) - Christine Zhou
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
Chương 5.Thuyết tương đối - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 4. Tán xạ ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 3.Phân cực ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
评论 (0)
暂无评论。快来抢沙发吧!