Save this video free

UNC COMP 301 - F26/Lec 5 - Polymorphism, Type casting, Method Access, Overriding methods

Muhammad Sayeed Ghani · 1:14:05 · Watch on YouTube

Part of UNC Chapel Hill COMP 301. See all 22 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Muhammad Sayeed Ghani explains Java polymorphism by separating a reference’s compile-time type from its object’s runtime type, then applies that distinction to upcasting, downcasting, type-hierarchy graphs, and method access. He connects inheritance to overriding, `@Override`, `super`, Java’s virtual method dispatch, and `final`, and closes with Java enums as named constants.

Key takeaways

Chapters

0:00 Compile-Time and Runtime Types in Java Casts
9:10 Testing Casts Between Students, Professors, and People
11:54 Building a Type-Hierarchy Graph for Classes and Interfaces
15:10 Using the Type Graph to Predict Cast Outcomes
22:00 Why Some Interface Casts Compile but Fail at Runtime
33:29 Disconnected Types Cause Compile-Time Cast Errors
37:10 Declared Type Controls Method Access
42:24 Downcasting Emily to Call Professor Methods
46:06 Object Methods and Casting from Java’s Root Type
49:48 Overriding `getName()` for Professor-Specific Output
56:36 `@Override`, Access Modifiers, and Calling `super`
1:04:59 Java Virtual Methods Dispatch to the Most Specific Override
1:10:47 `final` Prevents Method Overrides and Class Inheritance
1:12:37 Java Enums for Named Constants and Next-Topic Preview

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 Right. Good afternoon everyone. So I hope your um assignment number one went well. Uh for those of you who still haven't and I know there are some of you who still haven't submitted. So you do have till tomorrow night I believe uh to submit it late. It will be marked late. There is no penalty. However uh you know it's not good to have a late written next to your assignment. So I would suggest uh take advantage because after tomorrow night there will be no further extensions. Right. So let's pick up where we left off in the last lecture where we speaking about polymorphism and today we'll continue on talking about type casting and we'll take a look at a whole bunch of u issues which are related to polymorphism

0:51 and then from next week we'll go on to a completely new topic. So type costing. So this can be a little confusing and so I'm going to do a bit of a review. I believe we did uh come cover some of these slides in the last lecture but I think it's worth a review. So let's take a look at the following scenario. Um where you have a statement which says person Kim 1 is equal to new professor Kim. So what is that supposed to do? Well, if you take a look at the inheritance structure, what you have over here is Kim Jan being declared as person. And I like to put a little circle next to what the declaration is. And then uh

1:41 it's actually when it's instantiated, it comes to comes out to be a professor. And I'll just put a little square over here so that we know where those two things are. And now in the next statement, what we're doing is we're

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Muhammad Sayeed Ghani.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.