Loading topic
Dog class can extend an Animal class. That means every Dog is also an Animal. This chapter shows what that lets you do with variables.2 min readAnimal can hold a Dog or a Cat. You have also seen that a subclass can override a method. This chapter puts those two ideas together. When you call a method through an Animal variable, which version runs?2 min readsuper keyword lets you do that.2 min readstatic, private, or final are never chosen at runtime. This chapter shows what happens with each one.2 min readAnimal can hold a Dog. That is useful, but it has a limit. Through an Animal variable, Java only lets you call methods that Animal has. If Dog has an extra method, you need a way to get the Dog back. This chapter shows how to do that safely.2 min readObject, even when you never write extends. Object gives every class three methods that you will often override: equals, hashCode, and toString. The default versions rarely fit your own classes, so this chapter shows how to replace them correctly.2 min readnew. This chapter shows how that can surprise you and how to avoid it.2 min readarea() method, and Java picked the right one at runtime. This chapter shows a second way to get the same result. You list every allowed subtype up front, and then you handle each one in a single switch.2 min read