oop

1. Basic Inheritance & Method Overriding

Analyze the code, write your predicted output, and then reveal the solution.

Scenario

Demonstrate the fundamental "IS-A" relationship and how a subclass can provide a specific implementation of a method defined in its superclass.

Code Block
class Vehicle { void fuelType() { System.out.println("Generic Fuel"); } } class ElectricCar extends Vehicle { @Override void fuelType() { System.out.println("Electricity"); } } public class Main { public static void main(String[] args) { Vehicle v = new ElectricCar(); v.fuelType(); } }
Take Your Shot
Predicted Output

Type exactly what you think will be printed in the console.

1. Basic Inheritance & Method Overriding | DevExCode