Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Generating preview...
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.
Description
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 summary
- Document name
- Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- 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.
- Table of contents
- This document has no clear table of contents.
- Pages
- 1 pages
- Uploaded by
- Uni24h
Frequently asked questions
Is this document free?
Yes. “Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou” is free — just sign in and click Download to get the original file.
How many pages is this document?
The document has 1 pages, for the course Lập trình Java. You can preview it online before downloading.
Can I preview before downloading?
Yes. You can preview this document right on this page with the online reader, then decide whether to download.
Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Generating preview...
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.
Read full document
- Document name
- Inheritance notes (Discussion 4) (Kế thừa trong Java) - Christine Zhou
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- 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.
- Table of contents
- This document has no clear table of contents.
- Pages
- 1 pages
- Uploaded by
- Uni24h
Comments (0)
No comments yet. Be the first!
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
Comments (0)
No comments yet. Be the first!