Questions tagged [abstract]

abstract is a keyword shared by a multitude of object-oriented programming languages. Methods and classes can be marked abstract to indicate that they do not contain the full implementation of application logic and have to be extended. Abstract classes can not be instantiated and serve the purpose of providing a uniform interface for their subclasses, as well as the implementation of common methods that don't have to be reimplemented for each subclass.

abstract is a keyword shared by a multitude of object-oriented programming languages.

Methods and classes can be marked abstract to indicate that they do not contain the full implementation of application logic. Abstract classes can not be instantiated and serve the purpose of providing a uniform interface for their subclasses, as well as the implementation of common methods that don't have to be reimplemented for each subclass.

The exact meaning of abstract depends on the programming languages in question, some of them being: Java, C#, php, C++, Delphi Pascal. Similar logic can also be implemented using different keywords in other languages ( for example, Oracle PL/SQL allows to create abstract classes and methods by declaring them NOT FINAL)

The power of abstract methods and classes is widely used by design patterns.

2521 questions
116
votes
8 answers

Swift - class method which must be overridden by subclass

Is there a standard way to make a "pure virtual function" in Swift, ie. one that must be overridden by every subclass, and which, if it is not, causes a compile time error?
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
89
votes
9 answers

C++ Abstract Class: constructor yes or no?

A class with one (or more) virtual pure functions is abstract, and it can't be used to create a new object, so it doesn't have a constructor. I'm reading a book that provides the following example: class Employee { public: Employee(const…
user2452426
  • 991
  • 1
  • 7
  • 7
78
votes
9 answers

Precise definition of "functional interface" in Java 8

Recently I started exploring Java 8 and I can't quite understand the concept of "functional interface" that is essential to Java's implementation of lambda expressions. There is a pretty comprehensive guide to lambda functions in Java, but I got…
Anton Cherkashyn
  • 5,719
  • 6
  • 43
  • 80
75
votes
3 answers

Why give an "abstract: true" state a url?

I've be fiddling around with ui-router today in trying to better understand the scaffolding in Ionic and one thing that I noticed was that they give the abstracted state of "tabs" a url. The only times I've ever used abstract states, I used an…
spb
  • 4,049
  • 6
  • 22
  • 30
74
votes
2 answers

Scala's sealed abstract vs abstract class

What is the difference between sealed abstract and abstract Scala class?
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
73
votes
7 answers

How can I force a Constructor to be defined in all subclass of my abstract class

I have an abstract class A that define abstract methods. This means that, for a class to be instanciable, all the abstract method have to be implemented. I'd like all my subclasses to implement a constructor with 2 ints as parameters. Declaring a…
dodecaplex
  • 1,119
  • 2
  • 8
  • 10
73
votes
7 answers

Abstract constants in PHP - Force a child class to define a constant

I noticed that you can't have abstract constants in PHP. Is there a way I can force a child class to define a constant (which I need to use in one of the abstract class internal methods) ?
Alex
  • 66,732
  • 177
  • 439
  • 641
64
votes
13 answers

Abstract variables in Java?

I am coming from c# where this was easy, and possible. I have this code: public abstract class clsAbstractTable { public abstract String TAG; public abstract void init(); } but Eclipse tells me I use illegal modifier. I have this…
Pentium10
  • 204,586
  • 122
  • 423
  • 502
63
votes
1 answer

Comparison : interface methods vs virtual methods vs abstract methods

What are the advantages and disadvantages of each of these? interface methods virtual methods abstract methods When one should choose what? What are the points one should keep in mind when making this decision?
Nawaz
  • 353,942
  • 115
  • 666
  • 851
62
votes
5 answers

Not sure when to use an abstract property and when not

I'm not really sure what looks better or when do I really use in abstract classes and properties, or when to use non abstract properties. I'll try to make a simple example. Let's say I have this: abstract class Human { public GenderType Gender {…
miri
  • 1,611
  • 5
  • 20
  • 24
61
votes
4 answers

Can an enum have abstract methods?

Can an enum have abstract methods? If so, what is the use, and give a scenario which will illustrate this usage.
java_geek
  • 17,585
  • 30
  • 91
  • 113
61
votes
4 answers

Should I add an @Override annotation when implementing abstract methods in Java?

When overriding a non-virtual method in Java, use of the @Override annotation is recommended, but what if I implement an abstract method? Should I use @Override then as well?
Eyvind
  • 5,221
  • 5
  • 40
  • 59
59
votes
7 answers

What is the use of 'abstract override' in C#?

Just out of curiosity I tried overriding a abstract method in base class, and method the implementation abstract. As below: public abstract class FirstAbstract { public abstract void SomeMethod(); } public abstract class SecondAbstract :…
Manish Basantani
  • 16,931
  • 22
  • 71
  • 103
55
votes
8 answers

Java: static field in abstract class

I just start out with an example, that explains it best: public abstract class A{ static String str; } public class B extends A{ public B(){ str = "123"; } } public class C extends A{ public C(){ str = "abc"; …
Tommy
  • 551
  • 1
  • 4
  • 4
55
votes
5 answers

Can we use static method in an abstract class?

In Java Programming, Can we call a static method of an abstract class? Yes I know we can't use static with a method of an abstract class. but I want to know why.. ?
Neha Gupta
  • 847
  • 1
  • 8
  • 15