explain abstract method in javajava permits


Explain abstract method in java?

Java permits methods and classes to be declared abstract. An abstract method is not actually implemented in the class. It is merely declared there. The body of the method is then implemented in subclasses of in which class. An abstract method must be element of an abstract class. You create abstract classes through adding the keyword abstract after the access specifier, e.g.

public abstract class MotorVehicle

Abstract classes cannot be instantiated. It is a compile-time error to try something like
MotorVehicle m = new MotorVehicle();
when MotorVehicle has been declared to be abstract. MotorVehicle is in fact a pretty good instance of the sort of class that might be abstract. You're unlikely to be interested in a general motor vehicle. Rather you'll have trucks, motorcycles, cars, go-carts and other subclasses of MotorVehicle, but nothing which is only a MotorVehicle.

An abstract method gives a declaration but no implementation. Instead, it has no method body. Abstract methods can only exist inside abstract classes and interfaces. For instance, the MotorVehicle class might have an abstract fuel() method:

public abstract void fuel();

Car would override/implement this method also with a fuel() method which filled the gas tank along with gasoline. EighteenWheelerTruck might override this techniques with a fuel() method that filled its gas tank with diesel. ElectricCar would override/implement this method with a fuel() method that plugged into the wall socket.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: explain abstract method in javajava permits
Reference No:- TGS0284824

Expected delivery within 24 Hours