In this Java program, you have defined a class named FinalClass and a final class named Vehicle. A final class is a class that cannot be subclassed or extended by other classes. Here's an explanation of your program:
This program demonstrates the use of a final class. The Vehicle class is marked as final, making it impossible to create subclasses of it. This ensures that no other class can extend or inherit from the Vehicle class, making it a "leaf" class in the class hierarchy. When an object of the Vehicle class is created and its start method is called, it behaves as expected without the possibility of being overridden by any subclass.
public class FinalClass // Main class { public static void main(String[] args) { Vehicle vehicle = new Vehicle(); vehicle.start(); } } final class Vehicle // Final parent class { void start() { System.out.println("Vehicle starting ..."); } }
Vehicle starting ...
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions