answersLogoWhite

0

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

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How many constructor can be defined in a classin java p rogramming?

how many constructer can be defined in class in overloading of java programming


What is Abstract-Interface in java?

All interfaces are abstract.


What has the author D S Malik written?

D. S. Malik has written: 'Java Programming' 'Java programming' -- subject(s): Java (Computer program language) 'Fundamentals of abstract algebra' -- subject(s): Abstract Algebra, Algebra, Abstract 'C++ Programming'


Interface in java?

include all abstract method


Are all java stream class an abstract?

yes


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


What do mean by interface in java?

An interface in Java is like an abstract class, but there are no method bodies allowed in it and it has to be declared with the interface keyword. It is Java's way of getting around the Deadly Diamond of Death. Only abstract methods and constants are allowed in it.


Send mobile banking project using java abstract?

ikkk


Is built-in data-type are abstract data-types in java?

All built-in data types are not abstract data types.


What is interface in java?

Interface is collection of abstract methods which has only declaration and no implementation


What kind of constructs can be declared in a Java interface?

Constants and abstract methods. That's it.


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.