answersLogoWhite

0


Best Answer

Abstract keyword used for method declaration declares the methods without implementations.

Abstract class in java have abstract methods that is not implemented in abstract class, but implemented in subclasses in java program. If the class in java program is not required to get instantiated than that class use the abstract keyword but this class rather is available for other classes to extend by other classes.

Abstract keyword will be used in method declaration to declare that method without providing the implementation in that java program. In other words we can say that, it formally unfinished class as well as method, that marked with the help of keyword abstract.

Defining abstract is a way of preventing someone from instantiating a class that is supposed to be extended first. In java program abstract class is deliberately missing similar to like an interface which will missing all method bodies in the program. Abstract class provides a way to extend an actual class. We will not use new on abstract classes but will use abstract references in the java program, that always point to objects of the class that extends an abstract class.

In java program for practical use of an abstract class, we will define a non-abstract class that extends an abstract one. This will use any of the inherited non-abstract methods.

Most of the time abstract class may extend another abstract class. In that condition it need not implement all in the non-abstract methods. An abstract keyword used both on classes and methods. In case of class declared with an abstract keyword may not be instantiated that is the only thing that abstract keyword doing.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

An Abstract class is a special kind of class that cannot be instantiated. It has one or more methods which are not implemented in the class. These methods are declared abstract and they do not contain any code inside them.

Ex:

abstract class Parent {

public abstract String getSon();

public abstract String getDaughter();

....

....

//More methods that contain specific behaviour/code in them

}

The above is an abstract class "Parent" that has a lot of functionality but it has declared two abstract methods which have no code inside them. Any class that has one or more abstract methods has to be abstract. This abstract class cannot be instantiated.

i.e., the below piece of code will not work. The code will not even compile.

Parent object = new Parent();

Purpose of Abstract Classes:

Abstract classes are generally used where you want an amount of behaviour to be used by the class that extends the abstract class while at the same time giving options to the child class to provide a certain amount of behaviour itself.

A Child Class extending the Abstract Class:

public class Child extends Parent {

public String getSon() {

return "Sons Name";

}

public String getDaughter(){

return "Daughters Name";

}

...

... //Code specific to the Child class

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Abstract classes are used when you have several classes which share some common data or methods.

Sometimes it makes sense to have a concrete (non-abstract) base class, but other times an abstract class just makes more logical sense.

Let's look at an example using shapes.

You can have multiple different types shapes: triangles, rectangles, pentagons, etc. All of these things can be described by different classes, but they all share certain common ideas. For example, each shape has a perimeter and an area, but calculating those values differs for each one. This is where we would define methods in an abstract shape class.

abstract class Shape {

double getPerimeter();

double getArea();

}

Making Shape a concrete class wouldn't make much sense, since the perimeter and area would be undefined and meaningless for a generic shape. But an abstract class makes perfect sense, since it groups some of the common aspects of all shapes together.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

An abstract class can never be instantiated. Its sole purpose or rather mission in life is to be extended (subclassed).

Purpose of Abstract Classes:
Abstract classes are generally used where you want an amount of behaviour to be used by the class that extends the abstract class while at the same time giving options to the child class to provide a certain amount of behaviour itself.

A Child Class extending the Abstract Class:

public class Child extends Parent {
public String getSon() {
return "Sons Name";
}

public String getDaughter(){
return "Daughters Name";
}
...
... //Code specific to the Child class
}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

It has the same purpose as it does within every Object Oriented Programming (OOP) language.

Basically it allows programmer to not have to rewrite code over and over again in order to get the same functionality programmed once before.

It makes less work for the programmer and more concise code to be compiled.

Believe me, once you start writing a few hundreds or thousands of lines of code, you'll quickly find it to be a blessing.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Abstract classes are generally used where you want an amount of behaviour to be used by the class that extends the abstract class while at the same time giving options to the child class to provide a certain amount of behaviour itself.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is purpose of abstraction in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is abstraction method in java?

Abstraction in Java or Object oriented programming is a way to segregate implementation from interface and one of the five fundamentals along with Encapsulation, Inheritance, Polymorphism, Class and Object. Abstraction in Java is achieved by using interface and abstract class in Java.


What is Procedural Abstraction?

java supports procedural abstraction by means of constructors and methods. in java constructor and methods are always components of particular class. java supports coping parameter only. procedural abstraction is a principle in which the particular language supports some features through which procedures are modelled in the class hiding other details.


Why java is called truly object oriented language?

because java supports three main pillars.....(inheritance encapsulation and abstraction)..... and everything in java is OBJECT......


What are the functions of an interface in Java?

To create an abstraction or a blueprint for a class to implement later.


Is purpose an abstraction?

yes it is not tangible and is represented by a concept.


What is the purpose of NoMatchException handling method in java?

java exception


What is the purpose of vector?

The purpose of vector Java is to make more Java possibilities for mobile and uniformed devices. The makers of Java said that they wanted to "revolutionize" the way that Java works and helps around the globe.


What are basic java features?

features are: 1. Inheritance 2. Polymorphism 3. Data Encapsulation 4. Data Abstraction etc..


Define socket in java?

The Socket class in Java is an endpoint in a standard TCP connection. The Socket class implements methods which take care of all the overhead required with TCP communication.


What is the purpose of Java Mobile?

Java is the leading mobile phone developers and carriers. The purpose of Java's Mobile Media API is to play record sounds and videos and to also capture still images.


What is java's purpose on my PC?

Programs that are specifically designed with Java require a Java runtime to work on a computer. (In the case of Java, the runtime is called "Java Virtual Machine".) If you have any such program, you need to have Java.


How do you achieve abstraction in java?

Abstraction in Java is achieved using interfaces and abstract class. abstract means something which is not complete or concrete but abstraction itself is a great programming concept and allow you to write code which is more flexible to change.