menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Inheritanc...
source image

Medium

1w

read

59

img
dot

Image Credit: Medium

Inheritance and Polymorphism in Java| Understand These Concepts Better Through Actual…

  • Java concepts, like late binding, method overriding or overloading as well as to wahat point your program is going to allow your mistakes; I mean whether you are going to get a compile or runtime error.
  • Exercise 1: Calls Dog’s overridden sound method.
  • Exercise 2: Throws ClassCastException at runtime because v is not an instance of Car.
  • Exercise 3: Throws ClassCastException at runtime because p is not an instance of Child.
  • Exercise 4: Fails at runtime (ClassCastException) because obj is not an instance of C.
  • Exercise 5: Fails at runtime (ClassCastException) because s is not an instance of Circle.
  • Exercise 6: Throws ClassCastException because a is not an instance of Cat.
  • Exercise 7: Works because app points to a WashingMachine instance.
  • Exercise 8: Fails at runtime (ClassCastException) because f is not an instance of Apple.
  • Exercise 9: Calls the overridden method in Student.

Read Full Article

like

3 Likes

For uninterrupted reading, download the app