Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
1.3. Inheritance and Polymorphism
This section
Practice test
11 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
4 cards from this lesson. Good the night before a test.
Try these first
- 1.
What is inheritance in programming?
Hint
Think of family traits.
- 2.
Define polymorphism.
Hint
It relates to the Greek word meaning many shapes.
- 3.
What is inheritance?
- A way to share variables
- A method for acquiring properties of a class
- A method of coding style
Hint
Think of it as passing traits down.
- 4.
True or False: Polymorphism allows the same method to behave differently based on the object.
- True
- False
Hint
Remember the shape analogy.
- 5.
Design a simple class hierarchy involving a base class
Personand derived classesStudentandTeacher. Describe their interrelations and illustrate how inherited methods can be overridden.Hint
Consider how each derived class can extend from the base class while modifying behavior.
- 6.
Create a scenario involving an interface that utilizes polymorphism. Describe a
Shapeinterface and implement it in classesCircle,Rectangle, andTriangle, ensuring that the area method is polymorphic.Hint
Think about how the concept of shape can yield different results through the same method call.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
1 more question available
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting