0% found this document useful (0 votes)
12 views3 pages

Java Inheritance and Constructor Challenges

Uploaded by

Arya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Java Inheritance and Constructor Challenges

Uploaded by

Arya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🧪 HW PROBLEM 1: Light and LED Multiple Constructors

Topic: Constructor Chaining with this() and super()

Problem Statement:

Create Light class with multiple constructors using this(). Create LED class with
constructors using both this() and super().

Hints:

●​ Chain constructors using this() in same class


●​ Chain to parent using super() from child class
●​ Add print statements to trace constructor calls

🧪 HW PROBLEM 2: Tool Access Levels


Topic: Access Modifiers in Inheritance

Problem Statement:

Create Tool class with private, protected, and public fields. Create Hammer class and
test field accessibility.

Hints:

●​ Try accessing different access level fields from child


●​ Use getters for private fields
●​ Document which fields are directly accessible

🧪 HW PROBLEM 3: Game and Card Game Objects


Topic: Overriding Object Methods

Problem Statement:

1
Create Game class overriding toString() and equals(). Create CardGame extending Game
and override these methods properly.

Hints:

●​ Override toString(), equals(), and hashCode()


●​ Call [Link]() in child class override
●​ Test equality between objects

🧪 HW PROBLEM 4: Food Preparation Template


Topic: Template Method Pattern

Problem Statement:

Create Food class with template method prepare() that calls wash(), cook(), serve().
Create Pizza and Soup with different implementations.

Hints:

●​ Template method calls other methods in sequence


●​ Child classes override individual step methods
●​ Test template method on different food types

🧪 HW PROBLEM 5: Math Operations Inheritance


Topic: Inheritance with Method Overloading

Problem Statement:

Create BasicMath with overloaded calculate() methods. Create AdvancedMath


extending it and adding more overloaded methods.

Hints:

●​ Create multiple calculate() methods with different parameters

2
●​ Child class inherits all overloaded methods
●​ Add new overloaded methods in child class

🧪 HW PROBLEM 6: Weather System Hierarchy


Topic: Complete Inheritance Implementation

Problem Statement:

Create Weather → Storm → Thunderstorm (multilevel) and Weather → Sunshine


(hierarchical). Include constructor chaining, method overriding, and polymorphism.

Hints:

●​ Implement both multilevel and hierarchical inheritance


●​ Use constructor chaining throughout
●​ Override methods at different levels
●​ Test with polymorphic array of Weather references

You might also like