Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the base class method for movement.
LLD
class Piece { public void [1]() { // base movement logic } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated method names like 'run' or 'jump' which do not fit the context.
✗ Incorrect
The base class method for piece movement is conventionally named 'move' to represent the action.
2fill in blank
mediumComplete the code to override the move method in a subclass.
LLD
class Knight extends Piece { @Override public void [1]() { // knight specific movement } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name which does not override the base method.
✗ Incorrect
The subclass overrides the base class method 'move' to provide specific movement rules.
3fill in blank
hardFix the error in the method signature to correctly override the base method.
LLD
class Bishop extends Piece { public void [1]() { // bishop movement logic } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Changing the method name breaks overriding and polymorphism.
✗ Incorrect
To override correctly, the method name must be 'move' matching the base class method.
4fill in blank
hardFill both blanks to define an abstract base class and abstract move method.
LLD
abstract class Piece { public abstract void [1](); } class Queen extends Piece { @Override public void [2]() { // queen movement logic } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different method names breaks the abstract method contract.
✗ Incorrect
The abstract method and its override must have the same name 'move' to enforce polymorphism.
5fill in blank
hardFill all three blanks to implement polymorphic move calls for different pieces.
LLD
Piece p1 = new [1](); Piece p2 = new [2](); p1.[3](); p2.move();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names or method names breaks polymorphism.
✗ Incorrect
Create instances of Knight and Bishop, then call the polymorphic 'move' method on each.