Learn
Inheritance and Polymorphism
Review of Inheritance and Polymorphism
Excellent work! You’ve learned quite a bundle about inheritance and polymorphism in Java:
- A Java class can inherit fields and methods from another class.
- Each Java class requires its own file, but only one class in a Java package needs a
main()
method. - Child classes inherit the parent constructor by default, but it’s possible to modify the constructor using
super()
or override it completely. - You can use
protected
andfinal
to control child class access to parent class members. - Java’s OOP principle of polymorphism means you can use a child class object like a member of its parent class, but also give it its own traits.
- You can override parent class methods in the child class, ideally using the
@Override
keyword. - It’s possible to use objects of different classes that share a parent class together in an array or
ArrayList
.
Instructions
In the code editor, you’ll find a parent class Noodle
and some child classes to play around with. We invite you to experiment with what you’ve learned about inheritance and polymorphism!