answersLogoWhite

0

What is abstract base class?

Updated: 8/10/2023
User Avatar

Wiki User

17y ago

Best Answer

An abstract class is a class that cannot be directly instantiated. The purpose of such a class is to put some logic in a base class and force derived classes to implement the remaining functionality. Since the full functionality is only available in the derived class, the base class is declared as abstract so that it cannot be instantiated directly.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

A base class is a class that a derived class is based on. All of the methods and attributes of the base class are included in the derived class, with the methods and attributes of the derived class either adding to the base class, or replacing (overloading) those in the base class.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

An abstract class is a class that contains at least one pure virtual function. A definition is not needed for pure virtual functions, as derived classes must override them.

virtual void foo() = 0;

Abstract classes cannot be instantiated. They provide a template for derived classes, and you can also point to them with pointers to utilize polymorphism.

Additionally, a class derived from an abstract class must override ALL of the pure virtual functions, in order to make the class concrete. Implementing fewer than all of them will automatically make the derived class abstract, and instantiation of the derived class will not be possible.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

abstract is when you scribble lines and whenever you are done with scribbling the scribbles end up looking like a body or face and interface is when you draw all of the lines, joints, and bones in the human face. (trust me I went to class for abstract and interface!)

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

1>Abstract class is use to extends the only one class not more then one class

2>Abstract class can contant construct

2>Abstract class can contant static block and non-static block both

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

An abstract class is one that has one or more abstract methods. i.e., methods that have only a declaration and no implementation.

A fully abstract class is one that has only abstract methods and does not provide implementation to even one method in the class. A fully abstract class is equal to an interface.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

An Abstract method is one that has only a method declaration and no method definition. Similarly an abstract class is one that has one or more abstract methods.

You can declare an abstract class or methods by using the keyword abstract in the class definition.

Ex: public abstract class TestAbsClass {

abstract void method1();

}

Any class that extends this abstract class must provide implementation to the method "method1" or else it would have to be abstract as well.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

An Abstract class is a special kind of class that cannot be instantiated. It has one or more methods which are not implemented in the class. These methods are declared abstract and they do not contain any code inside them.

Ex:

abstract class Parent {

public abstract String getSon();

public abstract String getDaughter();

....

....

//More methods that contain specific behaviour/code in them

}

The above is an abstract class "Parent" that has a lot of functionality but it has declared two abstract methods which have no code inside them. Any class that has one or more abstract methods has to be abstract. This abstract class cannot be instantiated.

i.e., the below piece of code will not work. The code will not even compile.

Parent object = new Parent();

This answer is:
User Avatar

User Avatar

Wiki User

17y ago

A class that does not include an implementation and therefore cannot be directly used. It is used to derive other classes; the derived classes implement the methods.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is abstract base class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is an abstract class cannot have any member variable in C plus plus?

An abstract base class may have member variables. Whether or not it actually needs member variables depends on the nature of the base class itself. If the variable is common to all derived classes, then it makes sense to place the variable in the base class. If some derived classes have no need of the variable, then it is better to derive an intermediate class with the variable, and to derive those classes that require that variable from the intermediate class, rather than directly from the abstract class.


What is the logical abstrect base class for a class called CricketPlayer?

A logical abstract base class for a class called CricketPlayer could be Batsman class or Bowlerclass.


What kinds of game-related classes would be best implemented as abstract?

That would depend on what type of game you are developing. Unlike a concrete class which can be instantiated in its own right, an abstract class can only be instantiated through derivation. In other words, an abstract class can only be used as a base class, and is known as an abstract base class for that reason. We can also refer to them as abstract data type, given a class is also a type.We typically use an abstract base class to define a common interface for all its derivatives. If we need to divide the interface to cater for specialisations, we can derive intermediate base classes from the abstract base class. In this way we do not pollute the common base class with uncommon virtual methods.Abstract base classes typically have no data members and thus incur no memory overhead. However, if data members are required, they should be kept to a minimum and should only be declared if essential to the derivatives. Data members that are essential to some but not all derivatives should be placed in the appropriate intermediate class instead.In a game (or indeed any program) we might have many objects of many different types. However, objects that have a common public base class (including abstract base classes) can be treated as being "of the same type" (the common base). For instance, we might define an abstract Object base class such that all classes that publicly derive from the Object class can be treated as being of the same type (an Object).In a game we typically have objects that cannot be moved (static objects) and objects that can be moved (non-static). We can separate the two types of object by deriving Static and Nonstatic abstract base classes from our common Object class. We can then derive further intermediate classes from these two classes to cater for all the different types of object in our game. For instance, an armoury usually provides a choice of weapon and allows the user to select a primary and secondary weapon, thus we can derive a common Weaponabstract base class from our Nonstatic abstract base class, and then derive concrete (specific) weapons from the Weaponclass.


What can be declared in an abstract class?

Abstract classes are to be extended until to a concrete class.Can have both abstract & non abstract methods.An Abstract class can not be instantiated.A non abstract class can be extended to an abstract class.If At least one abstract method present in a class then that class must be abstract.abstract & final modifiers can never be together.abstract classes can have both abstract methods & non abstract methods.


What is an abstract class Write the syntax Declare a pure virtual function in an abstract class?

an abstract class is nothing but class which contains both abstract and concrete methods for abstract class we r nt create object Syntax for pure abstract class is abstract class x { public void abstract y(); public void abstract z(); public void abc() { }

Related questions

Is an abstract class cannot have any member variable in C plus plus?

An abstract base class may have member variables. Whether or not it actually needs member variables depends on the nature of the base class itself. If the variable is common to all derived classes, then it makes sense to place the variable in the base class. If some derived classes have no need of the variable, then it is better to derive an intermediate class with the variable, and to derive those classes that require that variable from the intermediate class, rather than directly from the abstract class.


What is the logical abstrect base class for a class called CricketPlayer?

A logical abstract base class for a class called CricketPlayer could be Batsman class or Bowlerclass.


What is the type of class for which objects can not be created except the static member?

Abstract data types or abstract base classes.


Why you are not allowed to put an abstract method into a normal class?

You can't put an abstract method (pure-virtual method) in a normal class because the normal class would become abstract itself. Only non-abstract classes can be physically instantiated as objects, and only if they fully implement all the abstract methods inherited from their base classes.


What kinds of game-related classes would be best implemented as abstract?

That would depend on what type of game you are developing. Unlike a concrete class which can be instantiated in its own right, an abstract class can only be instantiated through derivation. In other words, an abstract class can only be used as a base class, and is known as an abstract base class for that reason. We can also refer to them as abstract data type, given a class is also a type.We typically use an abstract base class to define a common interface for all its derivatives. If we need to divide the interface to cater for specialisations, we can derive intermediate base classes from the abstract base class. In this way we do not pollute the common base class with uncommon virtual methods.Abstract base classes typically have no data members and thus incur no memory overhead. However, if data members are required, they should be kept to a minimum and should only be declared if essential to the derivatives. Data members that are essential to some but not all derivatives should be placed in the appropriate intermediate class instead.In a game (or indeed any program) we might have many objects of many different types. However, objects that have a common public base class (including abstract base classes) can be treated as being "of the same type" (the common base). For instance, we might define an abstract Object base class such that all classes that publicly derive from the Object class can be treated as being of the same type (an Object).In a game we typically have objects that cannot be moved (static objects) and objects that can be moved (non-static). We can separate the two types of object by deriving Static and Nonstatic abstract base classes from our common Object class. We can then derive further intermediate classes from these two classes to cater for all the different types of object in our game. For instance, an armoury usually provides a choice of weapon and allows the user to select a primary and secondary weapon, thus we can derive a common Weaponabstract base class from our Nonstatic abstract base class, and then derive concrete (specific) weapons from the Weaponclass.


What can be declared in an abstract class?

Abstract classes are to be extended until to a concrete class.Can have both abstract & non abstract methods.An Abstract class can not be instantiated.A non abstract class can be extended to an abstract class.If At least one abstract method present in a class then that class must be abstract.abstract & final modifiers can never be together.abstract classes can have both abstract methods & non abstract methods.


What is an abstract class Write the syntax Declare a pure virtual function in an abstract class?

an abstract class is nothing but class which contains both abstract and concrete methods for abstract class we r nt create object Syntax for pure abstract class is abstract class x { public void abstract y(); public void abstract z(); public void abc() { }


What is the difference between abstract class and normal class?

Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods. We cannot create an object for the abstract classes. When we inherit the abstract class we should implement the abstract method which we inherit.


What should be structure of class when it has to be a base for other classes?

If a class is intended to be used purely as a base class then it must have one or more pure-virtual functions (a function that may or may not have an implementation). Such a class is regarded as being an abstract base class because no instances of the class can be instantiated other than through derivation, and the derivative must provide an implementation or it too becomes an abstract base class. The abstract base class need not declare a pure-virtual method if it inherits one or more pure-virtual methods from another base class but does not provide a complete implementation. Only classes that provide a complete implementation can actually be instantiated. Implementations may be inherited from lower base classes other than the one that declared the function pure-virtual in the first place. Once a derivative implements a pure-virtual function, that implementation may be inherited by subsequent derivatives. If the base class may be instantiated in its own right then it must not declare any pure-virtual methods, nor must it inherit any pure-virtual methods that have no implementations. In this case the base class may be derived from, but doesn't have to be derived from, whereas an abstract base class must be derived from.


How do you call an abstract class from main method?

An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.


True or false All methods in an abstract class must be abstract?

False. In fact, it is possible to have no abstract methods in an abstract class.


What happens if an abstract modifier is applied to class. Explain?

The classes which have one or more abstract methods are abstract. To declare a class as abstract, use the abstract keyword in front of the class keyword, before the class declaration. Abstract classes cannot be instantiated. Similarly the new keyword cannot be used to create an object of the abstract class. Remember that the constructors and static variables cannot be declared as abstract. Any subclass of an abstract class must either implement all of the abstract methods in the superclass or be itself declared abstract.