Java : Method Overriding - Exercises and Solution


1. Write a Java program to demonstrate method overriding with a subclass that overrides a method from its superclass

View Solution

2. Create a Java program to demonstrate method overriding with a subclass that overrides a method with a different return type

View Solution

3. Write a Java program to demonstrate method overriding with a subclass that overrides a method and calls the superclass method using the super keyword

View Solution

4. Create a Java program to demonstrate method overriding with a subclass that overrides a method and throws a subclass exception

View Solution

5. Write a Java program to demonstrate method overriding with a subclass that overrides a method and changes the access modifier to private

View Solution

6. Create a Java program to demonstrate method overriding with a subclass that overrides a method from an interface

View Solution

7. Write a Java program to demonstrate method overriding with a subclass that overrides a method from an abstract class

View Solution

8. Create a Java program to demonstrate method overriding with a subclass that overrides a method from a generic class

View Solution

9. Write a Java program to demonstrate method overriding with a subclass that overrides a method from an abstract class and implements an interface

View Solution

10. Create a Java program to demonstrate method overriding with a subclass that overrides a method from an interface and implements the same method with different behavior

View Solution

11. Write a Java program to demonstrate method overriding with a subclass that overrides a method and narrows the access modifier from public to protected

View Solution

12. Create a Java program to demonstrate method overriding with a subclass that overrides a method and broadens the access modifier from protected to public

View Solution

13. Write a Java program to demonstrate method overriding with a subclass that overrides a method from a superclass and adds a new parameter to the method

View Solution

14. Create a Java program to demonstrate method overriding with a subclass that overrides a method from an interface and implements a method with the same name but different parameters

View Solution

15. Create a Java program to demonstrate method overriding with a subclass that overrides a method and adds a new parameter with a default value

View Solution

16. Write a Java program to demonstrate method overriding with a subclass that overrides a method and changes the access modifier from public to private

View Solution

17. Create a Java program to demonstrate method overriding with a subclass that overrides a method from an abstract class and uses a lambda expression to implement the method

View Solution

18. Create a Java program to demonstrate method overriding with a subclass that overrides a method from an abstract class and changes the parameter list to accept a variable number of arguments

View Solution

19. Write a Java program to demonstrate method overriding with a subclass that overrides a method from a superclass and uses the same method name, parameter list, and return type while adding a checked exception

View Solution

20. Write a Java program to demonstrate method overriding with a subclass that overrides a method from an interface and changes the return type to a different class

View Solution



Basic Programs