An abstract method is one with only a signature and no implementation body. It is often used to specify that a subclass must provide an implementation of the method.
Questions tagged [abstract-methods]
186 questions
13
votes
4 answers
Is it good practice to override non abstract methods?
I have a situation where I need to modify the super class method to have a subclass specific logic, but the methods logic is same for all other subclasses.
I have two options:
1) make the method abstract and for each except my concerned subclass…

Learner
- 569
- 1
- 5
- 17
13
votes
2 answers
python abstractmethod with another baseclass breaks abstract functionality
Consider the following code example
import abc
class ABCtest(abc.ABC):
@abc.abstractmethod
def foo(self):
raise RuntimeError("Abstract method was called, this should be impossible")
class ABCtest_B(ABCtest):
pass
test =…

IARI
- 1,217
- 1
- 18
- 35
12
votes
3 answers
Overriding abstract methods in python
When overriding a python abstract method, is there a way to override the method with extra parameters in the method signature?
e.g.
The abstract class =
Agent(ABC):
@abstractmethod
def perceive_world(self, observation):
pass
The…

pseudogram
- 301
- 1
- 2
- 8
12
votes
11 answers
"Abstract static" method - how?
There are already several SO questions on why there is not abstract static method/field as such, but I'm wondering about how one would go about implementing the following psuedo-code:
class Animal {
abstract static int getNumberOfLegs(); // not…

polyglot
- 9,945
- 10
- 49
- 63
11
votes
5 answers
Changing abstract method signatures in inherited classes
Imagine I have a class called Engine as an abstract base class. I also have ElectrictEngine and FuelEngine classes which derive from it.
I want to create a method for refueling the engine.
Should I do it as an abstract method on the base class level…

Mulder
- 2,817
- 3
- 17
- 7
11
votes
2 answers
C++/CLI : How do I declare abstract (in C#) class and method in C++/CLI?
What is the equivalent of the following C# code in C++/CLI?
public abstract class SomeClass
{
public abstract String SomeMethod();
}

Lopper
- 3,499
- 7
- 38
- 57
10
votes
1 answer
Strange Default Method behavior with different Java versions
Let's say I have the following class hierarchy:
interface Collection
{
Collection $plus(E element)
}
interface MutableCollection extends Collection
{
@Override
MutableCollection $plus(E element)
}
interface Set…

Clashsoft
- 11,553
- 5
- 40
- 79
10
votes
2 answers
"TypeError: Can't instantiate abstract class" in Python
I have a module fi with the following classes defined:
class Asset(metaclass=abc.ABCMeta):
pass
@abc.abstractmethod
def get_price(self, dt : datetime.date, **kwargs):
''' Nothing here yet
'''
class CashFlows(Asset):
def…

user131983
- 3,787
- 4
- 27
- 42
10
votes
2 answers
overriding abstract methods in an inherited abstract class
Okay so basically I have the following problem: I'm trying to have an abstract class inherit another abstract class that has an abstract method, but I don't want to implement the abstract method in either of them because a third class inherits from…

thed0ctor
- 1,350
- 4
- 17
- 34
8
votes
3 answers
abstract method override in Derived class, how to make private
Hi I have a class "A" with as abstract method
protected abstract List GetContributors(List contributersList);
I want to override this method in derived class "B" with following conditions
It should be private to B…

Asad
- 21,468
- 17
- 69
- 94
7
votes
2 answers
Accessing a private element through an inline created object in java
I am new to java and trying some accessing methods and i encountered something that i do not understand. The code below working fine, prints 9 and not giving any compilation errors.
I think this code should give a compilation error and number…

rematnarab
- 1,277
- 4
- 22
- 42
7
votes
2 answers
Reasons behind why abstract and strictfp keywords cannot be used together in a method declaration?
I'm reading SCJP by katherine sierra.
I understand that abstract and final keywords cannot be used together because they contradict each other as explained in the book.
However, I don't understand why strictfp and abstract keywords cannot be used…

Ascendant
- 827
- 2
- 16
- 34
6
votes
3 answers
java.lang.AbstractMethodError: com.ibm.db2.jcc.t4.b.isValid(I)Z
Good evening,
I'm whith a problem on a project whith EJB Timer, I don't know what can I do to fix it.
there are a few methods in my project, all of them works well except "CargaC" When I call it I get a msg error:
My code:
public void CargaC() {
…

user3061516
- 105
- 1
- 1
- 11
6
votes
0 answers
abc.abstractclassmethod: Why is __isabstractmethod__ set on callable?
The implementation of abstractclassmethod abc.py in Python 3.4 looks like this:
class abstractclassmethod(classmethod):
__isabstractmethod__ = True
def __init__(self, callable):
callable.__isabstractmethod__ = True
…

someone
- 91
- 2
6
votes
4 answers
Creating new Abstract Method vs Interface Method
Q. Are you still following the principle of Program to an Interface if you are creating abstract methods in an abstract class that is not linked to an interface?
I use an Interface already for all of my UI classes that I have created; however, given…

Christopher Rucinski
- 4,737
- 2
- 27
- 58