+ 1

What is the use of abstract?

10th Jan 2018, 7:58 AM
Ilavarasan.T
4 Answers
+ 5
it's useful when u need to make many classes shared the same (or similar) functionality , so u make an abstract class and u make the other classes inherit from it , it gives a better description and structure for your project
10th Jan 2018, 9:31 AM
Maher Zaidoune
Maher Zaidoune - avatar
+ 1
An abstract class is used for polymorphism in the case when you do not want to create instances of the parent class.
10th Jan 2018, 10:24 AM
Sergei Khrapov
Sergei Khrapov - avatar
+ 1
When the system analyst or project manager makes a model of the software and designs the Class Diagram, he knows the general function of the software and the method signatures but he may not know the details of implementation. So he writes abstract classes and methods and give them to the programmers to write the body of the code and implement those classes and methods.
11th Jan 2018, 4:25 AM
Mahdi Hosseini
Mahdi Hosseini - avatar
0
In Java, abstract is applied to classes and methods. Abstract classes cannot be instantiated and typically have abstract methods, which have no implementation. This can be used to give a set of related classes some similar properties and functions, if they all extend this abstract class. An example might be: public abstract class BaseClass { public void setup() { // setup code here } public abstract void doStuff(); } public class ClassImpl extends BaseClass { // implementing abstract method public void doStuff() { super.setup(); // doStuff code here } } There could be many implementing classes following the same pattern, they do something different but need to be set up in the same way for example As a side note, an interface is an abstract class where all methods are implicitly abstract, there's no need to use the keyword in this case
10th Jan 2018, 8:07 AM
Dan Walker
Dan Walker - avatar