+ 1

Why one should declare abstract keyword to class when implementing few methods from interface??

What is the importantance of using abstract class??

30th Nov 2019, 9:03 AM
Manoj Prasanna
3 ответов
+ 5
An abstract class is similar to an interface (keeping aside the default and static methods) because all the methods inside an interface are abstract by default. Similarly if a class has an abstract method then the class containing it must be declared abstract but it is not necessary to have an abstract method inside an abstract class. Abstract classes are important because it gives you the privilege to override those methods in the class extending it so that you can have an object specific definition of the method you inherited. Just remember that an abstract class is like a structure which can be used to construct an object by extending it to a new class. I'm talking about inheriting and then creating an object of the subclass because abstract class cannot be instantiated. In simple words you cannot create an object of an abstract class.
30th Nov 2019, 9:57 AM
Avinesh
Avinesh - avatar
+ 3
Maybe this link can help you but all methods defined in Interfare should be implement either you using that methods or not. https://dzone.com/articles/when-to-use-abstract-class-and-intreface
30th Nov 2019, 9:13 AM
A͢J
A͢J - avatar
+ 2
You HAVE to declare a class abstract when you are not implementing the methods of an interface because only an abstract class can hold unimplemented methods. Or else if a class is not declared abstract then it is NECESSARY for the class to provide implementation for all the interface methods. That class will be called a concrete class.
30th Nov 2019, 1:42 PM
Avinesh
Avinesh - avatar