Questions tagged [abstract-class]

Abstract classes are classes which cannot be instantiated. They exist to provide common functionality and interface specifications to several concrete classes.

Abstract classes are classes which cannot be instantiated. They exist to provide common functionality and interface specifications to several concrete classes.

From Abstract Type on Wikipedia:

Abstract classes can be created, signified, or simulated in several ways:

  • By use of the explicit keyword abstract in the class definition, as in Java, D or C#.
  • By including, in the class definition, one or more methods (called pure virtual functions in C++), which the class is declared to accept as part of its protocol, but for which no implementation is provided.
  • By inheriting from an abstract type, and not overriding all missing features necessary to complete the class definition.
  • In many dynamically typed languages such as Smalltalk, any class which sends a particular method to this, but doesn't implement that method, can be considered abstract. (However, in many such languages, the error is not detected until the class is used, and the message returns results in an exception error message such as "does Not Understand").
5262 questions
2
votes
1 answer

Is it possible to test this Kotlin class?

I am trying to write unit test cases for a Kotlin class A and trying to mock return client() call present in test() method to unit test test() method: A.kt kotlin class: class A (par 1, par 2) : B(par 1, par 2) { override fun test(item: String):…
DR93
  • 463
  • 6
  • 21
2
votes
2 answers

Abstract classes and Polymorphism - how are additional methods and properties usually handled?

Imagine a rental company that has cars for the company to use internally and trucks to rent. The cars use gas and the trucks use diesel. The trucks have additional things that they do that cars do not - they are rented. So I have the following…
Eric Snyder
  • 1,816
  • 3
  • 22
  • 46
2
votes
2 answers

Python: abstract property type validation

I'm wondering, what is the best practices to handle abstract property type validation? from abc import ABC, abstractmethod class Base(ABC): @property @abstractmethod def name(self): """ :type str """ …
domin_1990
  • 25
  • 4
2
votes
2 answers

How to represent the Type of any Subclass of an Abstract class in Typescript?

Assuming abstract class A {}; class B extends A {}; class C extends A {}; I want to accept as a parameter any Subclass of A. function foo(Subclass: A){ const obj = new Subclass(); } This wont work. I get the error This expression is not…
Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120
2
votes
1 answer

How to force the definition of a destructor

I would like to force inheriting classes to define a destructor in Fortran >= 2008. So far I have tried several variations of: type, abstract :: parent_class_t contains final, deferred, pass :: cleanup end type which don't even compile. How do…
mcocdawc
  • 1,748
  • 1
  • 12
  • 21
2
votes
2 answers

Is there a way to extend a child component's constructor with a new Injection class without the need to call super()?

Within Angular I have child component which inherits from a parent component. This parent component injects multiple classes. I want to extend the child component with an injection class which I do not use in the parent class. Before this extension…
Klyner
  • 3,983
  • 4
  • 26
  • 50
2
votes
4 answers

Subclass editing declared abstract classes classmember

I have an abstract class that subclasses will inherit. I want to have a get method that returns the amount of passengers. I declare this method in the abstract class and it will return the passengers. The class member passengers is not defined but…
FatDog
  • 153
  • 1
  • 9
2
votes
2 answers

How to Call a Subclass Method From a SuperClass Object

lets suppose i have this Parent Class public abstract class Parent { private String name; private String surname; public Parent(String name, String surname) { this.name=name; this.surname=surname; } and lets suppose i have many child classes like…
FLM995
  • 41
  • 5
2
votes
1 answer

ARKit – Light Estimation

I am getting an error about init() not being available for ARLightEstimate. Code: class LightSensorManager { let lightEstimate = ARLightEstimate() // <-- error is here var ambientLightIntensity: CGFloat init() { …
2
votes
2 answers

Declaring an object of a subclass when the base class is abstract

I am learning about virtual functions and abstract classes and it seems that I have a difficulty in comprehending something. Let's say I have this code: class animal { public: virtual void show()=0; }; class dog : public animal { int…
PadK
  • 117
  • 1
  • 8
2
votes
2 answers

In java can inner classes inherit from an abstract class defined outside of the inner class's outer class?

In java can inner classes inherit from an abstract class defined outside of the inner class's outer class? Also can abstract classes implement constructors?
David
  • 14,569
  • 34
  • 78
  • 107
2
votes
1 answer

Interafce vs abstract class in overriding object class methods

Following code is compiling absolutely fine. To my understanding it should not be because Class C implementing interface I as abstract class fails to compile as well. interface I { public String toString(); } class C implements I…
T-Bag
  • 10,916
  • 3
  • 54
  • 118
2
votes
2 answers

Typescript - returning the constructor of a child class from an abstract method

I have abstract class Child and abstract class Parent as follows: abstract class Child { } abstract class Parent { abstract getChild(): typeof Child; // <-- want a class that extends Child } The idea is that both Parent and Child are extended…
user2503048
  • 1,021
  • 1
  • 10
  • 22
2
votes
0 answers

pure virtual method called terminate called without an active exception When the function does, it returns

Hi I'm doing a function to find a transport by number but I'm experiencing an error I don't know why. I have to abstract base class "Transport". class Transport { protected: int transportNumber; char transportName[20]; char company[20]; …
Amin abd
  • 21
  • 1
  • 2
2
votes
3 answers

Interface,Class Implementation and new method

This was a question asked to me in one of the interview. There is an interface "Iinterface" and 5 classes which implements this interface. Now i want to implement a new method MethodNew() only inside class3. What is the best approch for…
Vivi
  • 63
  • 5