Explain abstract method in java, JAVA Programming

Assignment Help:

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.


Related Discussions:- Explain abstract method in java

Dijkstra''s algorithm, How can I convert Dijkstra''s algorithm to do max fl...

How can I convert Dijkstra''s algorithm to do max flow instead of min flow, and how can I implement it into Ford Fulkerson algorithm?

Develop program using interactive brokers api, Develop Program using Intera...

Develop Program using Interactive Brokers API Project Description: We require a Matlab function using the Interactive Brokers API for real time trading with three arguments:

Explain jsp technology?, Java Server Page is a standard Java extension that...

Java Server Page is a standard Java extension that is described on top of the servlet Extensions. The goal of JSP is the simplified formation and management of dynamic Web pages. J

Develop android geolocation service app, Project Description: Develop an...

Project Description: Develop an android service app that will run on the background. The app has to get the users location (longitude and latitude) every 5 minutes or when th

I am requiring webcam software integrated into my site, I am requiring webc...

I am requiring webcam software integrated into my site I have website and I am wanting webcam software integrated into my site the company I have found doesn't offer support in

JAVA Programming, Im not in the line of computer science.But i would like t...

Im not in the line of computer science.But i would like to have some knowledge about the computer language "JAVA".I aldredy learns the computer languages "C,C++".So kindly help me

Decision structures, for $9.95 per month, 10 hours of access are provided.A...

for $9.95 per month, 10 hours of access are provided.Additional hours are $2.00 per hour

JAVA IF/ ELSE, #This assignment will give you practice with interactive pro...

#This assignment will give you practice with interactive programs, if/else statements and methods that return values. You are to write a program that prompts the user for informati

#tSutherland cohen line clipping algorithm, how do you write the code so th...

how do you write the code so the line will be clipped

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd