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

What is preferred organizational structure for organization, What is the pr...

What is the preferred organizational structure for the organization? The Network Organization is becoming the preferred organizational structure.

What do you understand by the term constructor in java, Question: (a) ...

Question: (a) What are the main differences between an object and a class? Illustrate with appropriate examples. (b) Differentiate between a global variable and a local va

Nested For-Loop, I''m having trouble with creating a nested for loop to cre...

I''m having trouble with creating a nested for loop to create a table that displays every number divisible by two within the given value. For example, if the number is 8 then there

Implement and test a program using java features, This assignment requires ...

This assignment requires you to design, implement and test a program using Java features from the first half of the subject content. You are required to implement in Java all the c

Applet, how to create a face with nose using applet

how to create a face with nose using applet

Confidentiality and privacy - security, The confidentiality and privacy may...

The confidentiality and privacy may be accomplished through encryption. Encryption may be: Private-key or symmetric: This is based on a single key. This needs the sender and the

Explain the relational operator precedence, Explain the Relational Operator...

Explain the Relational Operator Precedence ? Whenever a new operator is introduced you have to ask yourself whereas it fits in the precedence tree. If you seem back at the ins

Give an examples of java.lang.math methods, Give an Examples of java.lang.M...

Give an Examples of java.lang.Math Methods Here is an instance program in which exercises most of the routines in java.lang.Math. If your high school math is a little rusty, do

State about the jvm, State about the JVM? JVM is the acronym which ...

State about the JVM? JVM is the acronym which stands for 'Java virtual machine'. JVM provides execution environment. JVM isn't platform independent. JVM is Java

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