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

Difference between ejb 2.0and ejb 1.1, EJB 2.0 has the additional advantage...

EJB 2.0 has the additional advantages over the EJB 1.1 given below 1. Local interfaces : These are beans that can be needed locally, that means by the same Java Virtual Machi

Relation between stack and heap, Relation between Stack and Heap Stack ...

Relation between Stack and Heap Stack and heap are two significant memory areas. Primitives are created on the stack whereas objects are created on heap. This will be further c

Describe what is meant by a constructor in java, Question: (a) Describe...

Question: (a) Describe what is meant by a ‘constructor' in Java. Use a simple example to illustrate your answer. (b) Differentiate between a class method and an instance me

I want selenium based test automation for java, I want Selenium Based Test ...

I want Selenium Based Test Automation for Java Based Web Application Project Description: I want some test cases to be automated to login to UI which is Java based web applic

Prepare a game in corona, Prepare a Game in Corona (for Android and IOS) ...

Prepare a Game in Corona (for Android and IOS) Project Description: We are looking to prepare a game for mobile platform similar to Zombie Smasher for iOS and Android. Eve

Http 404 error /myproject/controller notfound, Running a sample Java web ap...

Running a sample Java web application from the web get http 404 error

What is synchronous messaging, Synchronous messaging involves a client that...

Synchronous messaging involves a client that waits for the server to respond to a message. So if one end is down the whole communication will fail.

Vigenere Cipher decryption unknown key, I need help writing this code eithe...

I need help writing this code either in java or in python. basically the steps are described here in this youtube video or">https://www.youtube.com/watch?v=LaWp_Kq0cKs or this is

Elaborate with examples vector or object oriented graphics, Elaborate with ...

Elaborate with examples Vector or Object oriented graphics? Vector or Object-Oriented Graphics treats everything which is drawn as an object. Objects retain their identity afte

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