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
5
votes
1 answer
django models - how can i create abstract methods
In django abstract classes seem to be posibble by using:
class Meta:
abstract = True
However I do not see how to declare abstract methods/functions within these classes that do not contain
any logic like e.g.
class…

Ilir
- 430
- 2
- 7
- 19
5
votes
6 answers
abstract method use vs regular methods
I would like to know the difference between two conventions:
Creating an abstract base class with an abstract method
which will be implemented later on the derived classes.
Creating an abstract base class without abstract methods
but adding the…

Mulder
- 2,817
- 3
- 17
- 7
5
votes
1 answer
Does the implementation of an abstract method in Java needs throws someException declaration if the abstract method has it?
In the superclass I have:
abstract someMethod() throws someException;
In the subclass I have:
someMethod(){/*do something*/}
Is it ok to do this without a throws someException declaration? Is it that the throws someException declaration is there…

Yulin
- 1,163
- 1
- 7
- 10
5
votes
1 answer
How to use generic EnumMap as parameter in abstract methods
I tried to use a generic EnumMap as paramter in an abstract method.
My Problem is that when I implement the abstract method with an existing enum for the EnumMap the compiler tells me that I have to remove the Override Annotation and implement the…

Dackelkotze
- 65
- 4
5
votes
1 answer
Is it pythonic to separate implementation method to be overridden?
I found it seems useful to separate abstract method into two methods, one for public interface, the other to be overridden by subclasses.
This way you can add precondition / postcondition check for both input and output, making it robust against…

niboshi
- 1,448
- 3
- 12
- 20
5
votes
7 answers
Abstract Methods don't have body?
I am new to Java (reading books for 4 months now). So probably my question can appear too simple. My understanding is that abstract methods don't have a body and can't provide implementation
So how does this works?
public abstract void fillRect (int…

Max_S
- 135
- 1
- 1
- 9
5
votes
10 answers
In Java, when should I use an abstract method in an interface?
I have the following interface in Java
public interface IFoo
{
public abstract void foo();
public void bar();
}
What is the difference between foo() and bar()?
When should I use abstract?
Both seem to accomplish what I want unless I'm…

John Oxley
- 14,698
- 18
- 53
- 78
4
votes
7 answers
Abstract class is using it's own abstract method?
I'm looking over some code in a game and I came across something that I haven't seen before and I don't really know whats going on.
public abstract class Entity
{
public Entity(World world)
{
// irrelevent code
…

Austin Moore
- 1,414
- 6
- 20
- 43
4
votes
0 answers
Should abstract methods have a body or not? Because in some websites it says as "yes" and other websites says "no"?
I understand that abstract methods forces the class which inherit it to implement those methods or the instances for these child classes can't be created. So abstract methods are templates for the child class from the parent class. But I dont…

Chethan CV
- 547
- 1
- 7
- 23
4
votes
4 answers
why would you need to know whether a method of an abstract class is abstract
I've been asked a question. It is the following:
The API documentation of an abstract class tells you whether a method
is abstract. When and why would you need to know this?
Any help would be appreciated.

bob
- 49
- 2
4
votes
1 answer
JAXB 2.x: Abstract methods get marshalled as Attribute
I have an abstract root class, let's say A.
And I have several implementation classes extending A.
A has FIELD annotation as well as some @XmlElement annotated properties.
A also has an abstract method.
When marshalling (B extends A), the value…

basZero
- 4,129
- 9
- 51
- 89
4
votes
1 answer
Abstract methods in Dart
I'm implementing an inheritance hierarchy in which derived-class construction consists only of a call to the base-class constructor. The base-class constructor then calls method(s) implemented only in the derived-class.
I have a basic…

Tom Russell
- 1,015
- 2
- 10
- 29
3
votes
1 answer
Abstract methods in c#
I honestly don't know why this is throwing me off.
public abstract class BankAccount
{
private string accNo;
private double balance;
public abstract void MakeWithdrawal(string acc);
public abstract void…

OVERTONE
- 11,797
- 20
- 71
- 87
3
votes
6 answers
abstract methods and overiding function in C++ and Java
In C++ and Java, or their respecting rules, what limits are placed on overiding abstract methods. Must you match the arguments or return type. I usually see abstract functions implemented with only a return type and no arguments, is it up to…

rubixibuc
- 7,111
- 18
- 59
- 98
3
votes
1 answer
force subclass to implement property python
Tried the answer from force-implementing-specific-attributes-in-subclass
But does not work. This code still passes with no errors.
#python version: 3.8.1
from abc import ABC, abstractmethod
class A(ABC):
@property
@abstractmethod
def…

Mas Zero
- 503
- 3
- 16