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
26
votes
4 answers

No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation

Consider the below code: class abstract Normal1 extends Something { } class Outer { class abstract Inner extends Normal1 { } } class General extends Outer.Inner // Problem occurs at this { } The error I am getting is "No enclosing…
user911333
  • 261
  • 1
  • 3
  • 4
26
votes
3 answers

static abstract methods in c++

I have an abstract base class class IThingy { virtual void method1() = 0; virtual void method2() = 0; }; I want to say - "all classes providing a concrete instantiation must provide these static methods too" I am tempted to do class IThingy { …
pm100
  • 48,078
  • 23
  • 82
  • 145
26
votes
6 answers

Which method is overridden?

Class A has run() method and interface B also has run() method. Question is simple, which run() method is overridden in Main class and how will we prove this? Why there is no conflict (Compile-time error) in this code? class A{ void…
Imam Bux Mallah
  • 393
  • 2
  • 7
25
votes
4 answers

How to force implementation of a method in subclass without using abstract?

I want to force subclass to implement an implemented method of my mother class. I look this Java - Force implementation of an implemented method but i can't convert my mother class to an abstract class. public class myMotherClass { myMethod { …
Maniz
  • 415
  • 2
  • 7
  • 17
25
votes
7 answers

How is abstract class different from concrete class?

I understand WHY we need Abstract Class in Java - to create sub-classes. But the same can be achieved by concrete class. e.g. Class Child extends Parent. Here Parent can very well be abstract & concrete. So why do we have ABSTRACT??
Ashish K Agarwal
  • 1,172
  • 3
  • 17
  • 33
24
votes
9 answers

C#: Creating an instance of an abstract class without defining new class

I know it can be done in Java, as I have used this technique quite extensively in the past. An example in Java would be shown below. (Additional question. What is this technique called? It's hard to find an example of this without a name.) public…
vipirtti
  • 1,058
  • 4
  • 15
  • 24
24
votes
1 answer

Passing parameters to the base class constructor

If the base class and derived class both have their constructors with parameters then where we pass the parameters to the base class constructors?
n.y
  • 3,343
  • 3
  • 35
  • 54
24
votes
5 answers

Java how to optional override method in abstract class?

Let's say we have a base class: public abstract class BaseFragment extends Fragment { ... protected abstract boolean postExec(); ... } And then derive from it to have other class(es) (e.g. Fragment_Movie, Fragment_Weather ...) public…
markbse
  • 1,023
  • 3
  • 13
  • 26
23
votes
3 answers

Why NullPointerException?

I have a abstract class and a derived class. Look at provided code:- public abstract class Parent{ public Parent(){ init(); } public abstract void init(); } public class Child extends Parent{ private String mTitle =…
VikasGoyal
  • 3,308
  • 1
  • 22
  • 42
23
votes
5 answers

Should an abstract class have at least one abstract method?

Is it necessary for an abstract class to have at least one abstract method?
java_geek
  • 17,585
  • 30
  • 91
  • 113
23
votes
9 answers

Why can abstract methods only be declared in abstract classes?

I understand that in abstract classes methods be both abstract, or not. But why can I not create an abstract method in a "normal", non-abstract class? Thanks in advance for any explanation!
Jona
  • 1,023
  • 2
  • 15
  • 39
22
votes
3 answers

I am unable to add an element to a list? UnsupportedOperationException

This one list object is biting me in the butt.. Any time I try to add an element to it, it produces this: Caused by: java.lang.UnsupportedOperationException at java.util.AbstractList.add(AbstractList.java:148) at…
Gray Adams
  • 3,927
  • 8
  • 32
  • 39
21
votes
4 answers

What happens when an abstract class implements an interface in Java

I am new to Java, coming from a C++ background and I try to understand the concept of interface and abstract class implementing an interface. What exactly happens when an abstract class implements an interface? Does this work like inheritance, i.e.…
AleC
  • 579
  • 3
  • 7
  • 15
21
votes
6 answers

Can an overriding method have a different access specifier from that in the base class?

Which access modifier, in an abstract class, do I have to use for a method, so the subclasses can decide whether it should be public or not? Is it possible to "override" a modifier in Java or not? public abstract class A { ??? void…
jam
  • 1,253
  • 1
  • 12
  • 26
21
votes
9 answers

Why does C# allow for an abstract class with no abstract members?

The C# spec, section 10.1.1.1, states: An abstract class is permitted (but not required) to contain abstract members. This allows me to create classes like this: public abstract class A { public void Main() { // it's full of…
Justin R.
  • 23,435
  • 23
  • 108
  • 157